Results 1 to 5 of 5

Thread: Datagrid delete multiple rows w/ complexity

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    73

    Datagrid delete multiple rows w/ complexity

    In VB 2003 I have a form app with a datagrid. Right now they can change things in the datagrid and click the cancel changes button if they want to undo. I want to be able to delete multiple rows without accepting changes until they are done. This seems to be a problem because the datagrid.currentRowIndex is no longer aligned with the datatable after you delete a row. I know I can align them if I acceptChanges but that is not what I want. Any help would be greatly appreciated.

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

    Re: Datagrid delete multiple rows w/ complexity

    Forget the grid. Work with the data source. If a row gets deleted then remember it by assigning it to a variable. If you want to undo you call that row's RejectChanges method and presto, it's undeleted. You can be notified when a row gets deleted from a DataTable by handling its RowDeleted event.
    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
    Lively Member
    Join Date
    Oct 2005
    Posts
    73

    Re: Datagrid delete multiple rows w/ complexity

    How would I delete the appropriate row though. For example if I delete the first row with the following code:
    VB Code:
    1. Me.objClientSummary.WP_ClientSummary.Rows(Me.grdWP_ClientSummary.CurrentRowIndex).Delete()

    If I delete the next one after that it sends the same index value and that row is already in the table in a deleted.

    If I can send a row object instead that would be great. But how?

    Remember I am trying to keep these rows in a deleted state until the user decides they are finalized at which point the changes to the table will be applied.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    73

    Re: Datagrid delete multiple rows w/ complexity

    How would I delete the appropriate row though. For example if I delete the first row with the following code:
    VB Code:
    1. Me.objClientSummary.WP_ClientSummary.Rows(Me.grdWP_ClientSummary.CurrentRowIndex).Delete()

    If I delete the next one after that it sends the same index value and that row is already in the table in a deleted.

    If I can send a row object instead that would be great. But how?

    Remember I am trying to keep these rows in a deleted state until the user decides they are finalized at which point the changes to the table will be applied.

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

    Re: Datagrid delete multiple rows w/ complexity

    Get the row from the table's DefaultView, not the table itself.
    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