Note that there are some explanatory texts on larger screens.

plurals
  1. POticker and dataset datagrid view c#
    primarykey
    data
    text
    <p>I modified the code, but I m still in trouble, all it's fine. Except when I modify the data into the XML file, the application crash. it Should be refresh the datagridview when I modify the data into the xml file.</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.Xml.Linq; using System.IO; using System.Threading; using System.Reflection; namespace XML { public partial class Form1 : Form { DataSet formBindingSource = null; public Form1() { InitializeComponent(); // formBindingSource = new DataSet(); using (FileStream stream1 = new FileStream("c:\\sites.xml", FileMode.Open)) { formBindingSource.ReadXml(stream1); } this.UpdateDataGrid(); dataGridView1.DataSource = formBindingSource.Tables[0]; // this.timer1.Enabled = true; this.timer1.Interval = 1000; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); FileSystemWatcher incoming = new FileSystemWatcher(); incoming.Path = @"c:\"; incoming.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName; incoming.Filter = "sites.xml"; incoming.Changed += new FileSystemEventHandler(OnChanged); incoming.EnableRaisingEvents = true; // // } public void OnChanged(object source, FileSystemEventArgs e) { using (FileStream stream1 = new FileStream("c:\\sites.xml", FileMode.Open)) { formBindingSource.ReadXml(stream1); } this.UpdateDataGrid(); dataGridView1.DataSource = formBindingSource.Tables[0]; } public void UpdateDataGrid() { if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate { UpdateDataGrid(); }); } else { //refresh column status evry second int count = 0; foreach (DataRow dr in formBindingSource.Tables[0].Rows) { DateTime SystemTime = Convert.ToDateTime(DateTime.Now); DateTime StartTime = Convert.ToDateTime(dr[0]); DateTime EndTime = Convert.ToDateTime(dr[1]); if (StartTime.TimeOfDay.Ticks &lt;= SystemTime.TimeOfDay.Ticks &amp;&amp; SystemTime.TimeOfDay.Ticks &lt; EndTime.TimeOfDay.Ticks) { formBindingSource.Tables[0].Rows[count][5] = "ok"; } else { formBindingSource.Tables[0].Rows[count][5] = "nok"; } count++; } formBindingSource.Tables[0].DefaultView.RowFilter = "date = #" + DateTime.Today + "#"; } } private void timer1_Tick(object sender, EventArgs e) { this.UpdateDataGrid(); this.label1.Text = DateTime.Now.ToString("dddd, MMMM dd, yyyy hh:mm:ss tt"); } } } </code></pre>
    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