I have a Dictionary (Of long, Class)
. The Class has multiple properties. And I want to view the data of this Dictionary in a DataGridView. So, Simply I used the:
DataGridView1.DataSource = Dictionary.Values.ToArray
Now, the properties inside the Class objects for the records inside the Dictionary are continuously updating (too frequent). And I want to reflect these updates to the DataGridView directly.
Using the DataGridView1.DataSource = Dictionary.Values.ToArray
every time is not an efficient way I believe and will take much processing power. How can I make the Dictionary Bindable (as in DataTables for example)? I need this in VB.NET, I tried to use Linq to solve this (Found here https://stackoverflow.com/a/855954/2546348 ) But still, I didn't see the new updates coming to DataGridView.
Any suggestions? What will be the best approach to implement this?
Thanks to @jimi's comment, I used the notify property to achieve this... But I needed to put an answer to this question:
Your class object should implement INotifyPropertyChanged
. When done, you can bind your [Dictionary].Values
to a BindingSource, then bind the DGV to the BindingSource (setting the DGV's .DataSource = [TheBindingSource]
). Any change to the Dictionary values will be immediately reflected in the DGV.
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.