0
I’m creating a C# order screen with Windows Forms in which the user fills in the order item data and then clicks on an "Add" button, which instantiates a Pedidoitem object, adds it to a list and then assigns that list to the Datasource of a Datagridview. So far so good.
Problems occur when the user clicks on the grid. Although it has the Readonly property enabled, the Allowusertoaddrows, Allowusertodeleterows properties disabled and the Editmode property set to Editprogrammatically, when it receives any click, the grid pops the error message "The -1 index has no value.".
I wish I could block changes on this grid, only allowing the user to select lines so that I can delete them through a button that will be implemented later.
Maybe it’s something extremely basic, but although I’ve already researched a lot on Google I haven’t found any plausible solution yet, so any help will be very welcome!
Grateful!
Regardless of the changed properties in your Datagrid control, you need to check the events associated with it, if you create a new grid, you will notice that the error will not be displayed.
– Ismael
You must be setting -1 on the grid Row Current somewhere in your code.
– Guilherme Barros
Ishmael, it somehow worked. Even when I pasted the same grid back up from a project backup. I ran a lot of tests on the properties here, but I couldn’t get anything. Anyway, the important thing is that it worked, understand the error will have to stay for the next. Thanks anyway!
– Tiago