I dont understand DataGridViews

So the title basically sums it up.

What I have:

  • A List of Objects of a custom class. The class defines a ToString method.
  • A WinForms…form… with a DataGridView on it.
  • The list will change during the usage of the program.

What I want:

  • The Datagridview to show the list of strings created by Select’ing the List into the ToString method.
  • When the List of Objects updates, to be able to regenerate or update the DataGridView.
  • The rows in the DataGridView can be deleted by the user (which then triggers a reverse process to clean up the List of Objects)

What happens currently:
Depending on which odd convoluted 6-layer deep DataSource/BindingSource/BindingList/PickAnotherSolutionFromGoogle I use, I either get a blank row or a row with 2 columns, one of which just contains the length of the string.

Why is this so difficult…

1 Like

Because its Microsoft :smiley:

SCNR

2 Likes

Hey, have you tried looking at Google material 3 docs? That’s right, there are none. You have to use the material 2 ones, and even then, there’s plenty of components that still only have “to do” as content. At least Microsoft has excellent documentation.

I do not understand all of what you are saying.

If I understand this then one possibility is to set the DataSource (or whatever specifies where the data is) to null then set it again. It has been a while since I have done Windows Forms.

The solution Microsoft wants us to use is to make the List of Objects an ObservableCollection and to implement INotifyPropertyChanged for the properties in it. I agree that this stuff seems unnecessarily convoluted. The intent however is to make it automatic; that we do not need to regenerate the view.

If I understand then that is more of a matter of the database. After the database is updated (or maybe after the entity is updated) an ObservableCollection will trigger the relevant update of the view.

I am in a reverse situation. I use a WPF window to edit an entity and the corresponding grid is also updated but if the cancel button is clicked then the edit needs to be reversed. I will not get into details here since it does not help you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.