Click here to Skip to main content
15,072,209 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a datagridview with "allow users to add new rows". It's binded to a database. The second column in this datagridview is readonly and when the user enter in this cell I show a treeview. (I assign the size and location of treeview to the size and location of the cell. When select a node into the treeview I fill the cell in the datagrid with the node name of the treeview.(I hope you can understand me, first of all sorry by my horrible english). It's more, I just start with C#, I am a total newbie)

Well, it,s work fine except when I do this operation in the row "new record" (the last row with the asterisk. Just in this row the treeview appears but when I click into the treeview it doesn't fill the last cell, and the treeview goes to the row before.
I tried to open a new row in differents events (Cell enter, cell click, DefaultValuesNeed) but I can't get it to work the way I want.
So, I appreciate all kinds of ideas.
Thanks in advance and best regards.

What I have tried:

I tried to open a new row in differents events (Cell enter, cell click, DefaultValuesNeed) but I can't get it to work the way I want
Posted
Updated 14-Nov-20 22:19pm

1 solution

All this would be easier if you used a "form" to add a new record: more control.

Since you have it working in "edit" mode, I suggest that when the user wants to "add a new record", you add it immediately (to the grid) with defaults, flag it as "in progress", and go into edit mode.

If the record turns out to be invalid, delete it (from the grid).

Understand this is just happening in the grid; you're not doing any "posting" to the DB until the "new" row has been validated / accepted.
   
Comments
Member 14945943 15-Nov-20 6:36am
   
Hi Gerry, I have already tried to create a empty record (with values depending on column format) when the user click over the row corresponding to a new record, but it is not so easy: As the table in the datagridview is binded, it is not possible to add records easily. I can do it in the DefaultValuesNeeded event, but to my surprise it adds two new rows (amazing but true).
In any case, thanks for trying to help me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900