c# - DataGridView editable cell input overwritten when another cell is updated -


i have datagridview bound through bindingsource datatable, , grid has editable columns user inputs value, , read-only columns programmatically updated in real time (think stock ticker). programmatically updated columns updating value in datatable , value in datagridview updated because of databinding. issue i'm having while user editing 1 cell, if cell updated programmatically text user has inputted in first cell gets overwritten (reset cell's value before edited).

this doesn't seem unusual situation me, can't seem work properly. know might doing wrong, or can point me towards example shows how properly?

this happening because when underlying value in datatable changes, datagridview.databindingcomplete event gets fired - resetting bindings.

my first suggestion capture event , check if editedformattedvalue currentcell different value - if so, set value. worked - until checked first row - ignored logic.

the solution find work change how programmatic real-time updates happened. if possible, instead of updating datatable columns, update datagridview columns. these changes perpetuate source binding not reset - current editing cell not lose changes.

foreach (datarow row in this.table.rows) {     row[1] = somenewvalue; } 

foreach (datagridviewrow row in this.datagridview1.rows) {     row.cells[1].value = somenewvalue; } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -