I am using a set of DataGridViews (dgv) to display a class's members via properties. I use the dgv so that the user can edit the value of the member right in the view (so I dont have to display a form or a textbox for editing that value).
The structure of the class I am displaying is as follows
Class1 (Displayed in a list view)
Collection Of class2 (Displayed in a dgv, we'll call it dgv1)
Collection of class3 (Displayed in a dgv, we'll call it dgv2)
Class3 exists because a collection of strings does not show up as strings in a dgv. (The length is displayed in the dgv.
Class2 and Class3 have string properties that I want editable in the dgv, so they are the only values displayed in the dgv.
When I add a new instance of either class2 or class3 to their respective parent class, I rebind the dgv displaying the collection.
After adding the new instance of the class, it appears in the dgv, but if I go to select the value (by clicking on it in the dgv) I get an exception stating "Index -1 does not have a value"
The issue does not occur if I save the information edited into the form and then reopen the form. The values that I could not previously edit are editable without issue.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…