Updating datagridview in Window application
I have a table with 6 columns ID,A,B,C,D and E. ID is primary key. An third party application keep updating Column D and E and also adding new rows to the table.
I want to display this table to a datagridview control. I am trying to update it each after 5 sec. So far i have tried:
Table may have 3-100 records.
//dt is a DataTable with new data
//dtPos is DataTable currently bind to datagridview
foreach (DataRow r in dt.Rows)
{
dtPos.DefaultView.RowFilter = "ID = '" + r["ID"].ToString() + "'";
if (dtPos.DefaultView.Table.Rows开发者_C百科.Count > 0)
{
dtPos.DefaultView.Table.Rows[0]["D"] = r["D"];
dtPos.DefaultView.Table.Rows[0]["E"] = r["E"];
}
else
{
dtPos.Rows.Add(r);
}
}
This did not seem to work as expected. any better idea?
hi i suggest you to do above your task in gridview itself so you can do it instantly insteed of doing it in table and then assigning it back to the datagridview. dgv have add row method so you can add row in dgv directly .
use like this when u need to add new row
dgv.Rows.Add(1,2,3,4,4,5);
and when u need to change the value of the cell then
dgv.rwos[roindex].cells[cellindex].value = xxx; //your new value;
this can help u ....
精彩评论