c# - sync data grid view -
i have data grid view data source data table in form in c#, how can make read table database continuously mean if program running in many computers in same network , connected same database , if computer 1 add row database appears automatically in computer 2 without clicking button refresh.
void load() { c.connect("sel_dep"); c.com.commandtype = commandtype.storedprocedure; sqldataadapter da=new sqldataadapter (c.com); datatable dt = new datatable(); c.open(); int last = 0; while (true) { if (dt.rows.count > 0) dt.rows.clear(); da.fill(dt); dd = dt; if (dt.rows.count != last) { last = dt.rows.count; this.invoke((methodinvoker)delegate { datagridview1.datasource = dt; datagridview1.selectedrows[0].selected = true; label1.text = datagridview1.rowcount.tostring(); }); } } c.close(); } private void form3_load(object sender, eventargs e) { aa = new thread(() => { load(); }); aa.start(); }
this tray
if using winforms create desktop application, not need timer
.
simply drag , drop timer
control toolbox on form, in design mode.
' form load should altered below private void form3_load(object sender, eventargs e) { ' assume timer control named 'otimer' otimer.enabled = true; otimer.interval = 60000; ' in milliseconds, equates 1 minute otimer.start(); }
create tick
event timer
. event fired each time interval elapses.
private void otimer_tick(object sender, eventargs e) { <call function initiate/refresh datagrid.datasource within event> }
in order further understand how timer
class works, refer timer class (system.windows.forms).
also refer stackoverlow question winforms timer dummies plenty of resources , tips master timer
control.
Comments
Post a Comment