✅ How can I replace a value in a 2D array, then refresh a datagridview with the new array
14 Replies
here is the console version for the replacing a data in the 2d array
this is the refreshing the datagridview
when on load it displays the array but when i replace a value and then call it it doesnt resfresh
the console version works perfectly fine

????
I haven't used WinForms in a while and have definitely not used data grids so I don't know how the data is binded but at a quick glance it sounds to me like you need to implement
INotifyPropertyChanged
and call the property changed event when you change the data so that it notifies the UI that the data has changed and it needs to update. Again, it might be a problem in how you are setting the data inside the data grid but if your data grid has a binding to the data I'd say the most probable suspect is not calling the PropertyChanged event from INotifyPropertyChanged
.i mean it loads the initial array right
it just doesnt change when the array does
Yes that is exactly the cause of not calling the PropertyChanged event.
but i can see from the console the array changes its just that the datagridview not changing
Because that event tells the UI that the initial data has changed and it needs to update the view to show that data change.
okay
could you give a short example of using the INotifyPropertyChanged
How to: Raise Change Notifications Using a BindingSource and the IN...
Learn how to raise change notifications using a BindingSource and the INotifyPropertyChanged Interface.
aight ill try this ty
The example code is too big and can confuse you, focus on INotifyPropertyChanged, PropertyChanged event and the NotifyPropertyChanged method
That is what you need to implement, and then call NotifyPropertyChanged method every place you change the data or better yet if your data is stored in a property to just call it in the
set
accessorClosed!
ty