Can't update datagridview and form elements in C# -


in c# using visual studio express 2013, trying update datagridview event handler button click. button submit button updates sqlite database , updates datagridview reflect change. problem after update sqlite database (which updating successfully) datagridview doesn't update event handler (this set in getloggeddata(employeenumber, false) reference). (i tried updating text box, didn't update). after datagridview supposed update, added thread.sleep, user can see changes made before datagridview resets (getloggeddata() on last line of button click resets datagridview).

the getloggeddata(employeenumber, false) method gets sqlite database datatable , sets datasource dgvlogged. check column , addrow shouldn't related problem.

as side note, have tried using binding source no avail.

// when button submit clicked private void btnconfirmentry_click(object sender, eventargs e)     {         modifyemployeejobs();          getloggeddata(employeenumber, false);         thread.sleep(2000);          getloggeddata();     }  public void getloggeddata(string empid, bool addrow)     {         dgvcolumnnumberadder = 1; // adds 1 index if checkboxes present in datagridview         mysql sql = new mysql();         try         {             dgvlogged.columns.clear();              datagridviewcheckboxcolumn checkcolumn = new datagridviewcheckboxcolumn();             checkcolumn.name = "check";             checkcolumn.headertext = "";             checkcolumn.width = 50;             checkcolumn.readonly = false;             checkcolumn.fillweight = 10; //if datagridview resized (on form resize) checkbox won't take much; value relative other columns' fill values             checkcolumn.minimumwidth = 30;             dgvlogged.columns.add(checkcolumn);              datatable dt = sql.getloggeddata(empid);              if (addrow)             {                 // add row datatable job information received                 datarow row;                 row = dt.newrow();                 row["empid"] = employeenumber;                 row["job"] = jobnumber;                 row["workcode"] = workcode;                 row["jobstate"] = "pending";                  dt.rows.add(row);             }                              dgvlogged.datasource = dt;             dgvlogged.columns[jobtrackingcolumnnumbers["id"] + dgvcolumnnumberadder].visible = false;             setcheckstates();             dgvlogged.visible = true;             txtinstructions.visible = false;         }         catch (exception ex)         {             messagebox.show(ex.tostring());         }     } 

the problem happening because doing thread.sleep() on ui button event- locks thread button event happens on until sleep complete.

you not want thread sleep in ui. if want user able navigate 2 seconds can kick off system.timer that, on elapsed finishes rest of logic wanted do. sleeping within button call lock ui because ui thread still running, , sleep it, waiting on sleep finish (on thread) before moving next step rebind data.

i cannot think of reason sleep on ui thread, ui display only, want trigger updates events , invokes. remember form multithreaded environment if not managing threads.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -