Note that there are some explanatory texts on larger screens.

plurals
  1. PODatagridview formatting issues
    primarykey
    data
    text
    <p>I load an XML file, I transfer the data to the dataset and I display with the datagridview1.</p> <p>I have 3 colums: start, end, and status.</p> <p>The format of column start is datetime like 8:00 AM</p> <p>The format of column end is datetime too like 10:00 PM</p> <p>Status is two values: ok or nok.</p> <p>I need to compare the datetime system with the start column and the end column, if the date system are between the two value, I display ok in the row. I need to do that for each row. for ok I need to change the background color to green and nok will be red. could you help me? .... I m lost between the dataset and the datagridview. thanks a lot </p> <p>Thank you guys for your help : I modified a little the code, given by you :)</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; using System.Globalization; using System.Security.Permissions; namespace tab { public partial class Form1 : Form { public Form1() { InitializeComponent(); DataSet ds = new DataSet(); ds.ReadXml("C:\\Sites.xml"); int count = 0; foreach (DataRow dr in ds.Tables[0].Rows) { string s1 = dr[0].ToString(); string s2 = dr[1].ToString(); string timeSys = DateTime.Now.ToString("hh:mm tt"); TimeSpan Start = DateTime.ParseExact(s1, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; TimeSpan End = DateTime.ParseExact(s2, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; TimeSpan Now = DateTime.ParseExact(timeSys, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; if (Start.Hours &lt; Now.Hours &amp;&amp; Now.Hours &lt; End.Hours) { ds.Tables[0].Rows[count][2] = "OK"; } else { ds.Tables[0].Rows[count][2] = "NOK"; } count++; } dataGridView1.DataSource = ds.Tables[0]; for (int icount = 0; icount &lt; dataGridView1.RowCount-1; icount++) { DataGridViewRow theRow = dataGridView1.Rows[icount]; if (theRow.Cells[2].Value.ToString() == "OK") theRow.Cells[2].Style.BackColor = Color.Green; else theRow.Cells[2].Style.BackColor = Color.Red; } } } } </code></pre> <p>I have still an issue, I didn't see the color displayed in the datagridview.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload