|
-
May 15th, 2013, 04:33 AM
#1
Thread Starter
Addicted Member
Hide next new row in DGV, while editing a new row.
My problem:
the user clicks add-new-row-button, and an empty new row is shown by setting the DGV.AllowUserAddRows to true and selecting the first cell to enter. As Soon as the user types the first letter in cell, the next new row gets displayed. I want the next new row to be hidden, as long as the current new row has not been finished.
I tried to set the AllowUserAddRows property of the DGV to False, as soon as the user Enters/starts-edit a cell in the just started new row, but this throws an exception
Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.
Please give me some advice.
-
May 15th, 2013, 05:19 AM
#2
Re: Hide next new row in DGV, while editing a new row.
If you want the user to have to click a Button to add a new row then you need to set AllowUserToAddNewRows to False. By setting it to True you are telling the grid to display an extra row at the bottom that the user can just type into to add a new row. If the user has to click a Button to add a new row then the user is not allowed to add new rows; it can only be done in code, i.e. the code that you execute when the Button is clicked.
-
May 15th, 2013, 08:25 AM
#3
Thread Starter
Addicted Member
Re: Hide next new row in DGV, while editing a new row.
Thank you for your comment. I think you misundrestood me. Now I set the AllowUserAddRows=true only after the user clicks the addnewrow button. So then this new row appears. Then the user starts to input data, and at this very moment the next new row is displayed, so that the user could jump to the next new row right away. I want him to be able to add only one new row each time he clicks add new row. I tried to add a new row by code, but I get an exception telling me, that I cannot add a row to a DGV bound to a datasource.
-
May 15th, 2013, 08:41 AM
#4
Re: Hide next new row in DGV, while editing a new row.
 Originally Posted by AndyLD
Thank you for your comment. I think you misundrestood me. Now I set the AllowUserAddRows=true only after the user clicks the addnewrow button.
Well don't. Don't change that property value at all. If you are using a Button then it should be False at all times. When the user clicks the Button then you add the new row in code. That's it, that's all.
-
May 15th, 2013, 10:13 AM
#5
Thread Starter
Addicted Member
Re: Hide next new row in DGV, while editing a new row.
Thank you very much, now it's clear to me, I have to add the row to the datatable bound to the grid. When I got the exception, that I cannot add a row to a databound DGV, I concluded, that one cannot add a row, I didn't think one step further.
-
May 15th, 2013, 06:43 PM
#6
Re: Hide next new row in DGV, while editing a new row.
Ideally, you would bind the DataTable to a BindingSource and then bind the BindingSource to the grid. You would then call AddNew on the BindingSource. The issue with adding a row directly to the DataTable is that an empty DataRow may violate non-null constraints. By using the BindingSource, the new row is created but not added to the DataTable until the user navigates away from the row or you call EndEdit on the BindingSource in code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|