Results 1 to 6 of 6

Thread: Hide next new row in DGV, while editing a new row.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2013
    Posts
    134

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2013
    Posts
    134

    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Hide next new row in DGV, while editing a new row.

    Quote Originally Posted by AndyLD View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2013
    Posts
    134

    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.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width