简体   繁体   中英

Two-way binding for DataGridView

I use DataGridView which is bound to the collection of objects which implement INotifyPropertyChanged interface. So, DataGridView is updated properly whenever properties of objects are changed (they are changing constantly taking their values from a device through a serial port).

The challenge is that I need two-way binding. But when I start editing DataGridView manually, when PropertyChanged event is raised for currently editing object, I get the following InvaliedOperationException: "Cross-thread operation not valid: Control 'dataView' accessed from a thread other than the thread it was created on".

The question is: what strategy I can use to allow editing values and displaying them simultaneously in the DataGridView control?

Just a suggestion, you can use the BackgroundWorker class and use the DoWork to perform the data binding. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM