Operation cannot be performed in this event handler - Error while updating datasource of datagridvie

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I have a datagridview which is bound to a datatable. (Not using Binding Context or DataBindings. I have kept it simply as dgv.DataSource = dt).
I have a details-like view (comprising textboxes, datetimepicker, etc.) below this grid.
Inside RowEvent eventhandler, I populate data (from DGV) into the above-said controls (again, these controls are not databound, due to some constraints / bitter experiences with databinding). When the user changes data in any of this details-view, I update
the DGV.

<div style="color:Black;background-color:White; <pre>
dgSubj.DataSource = <span style="color:Blue; null;
dgSubj.DataSource = dtSubj; <span style="color:Green; // dtSubj now contains latest data which was written to DB
[/code]

While re-binding, C# throws an error "Operation cannot be performed in this event handler".
While I understand theoretically that a DGVs source cannot be reset while in RowEnter / RowLeave event handlers, is there a work-around to refresh the grid? I have also tried various stuff like using bindingsource as datasource for DGV, and refreshing the
bs, etc. but nothing works!
Many Thanks <hr class="sig Sathya

View the full article
 
Back
Top