Results 1 to 7 of 7

Thread: [02/03] Which Row is deleted

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    81

    [02/03] Which Row is deleted

    hi all. I have a datatable(dt), and a datagrid(DataGridT) in a form. datatable bind to datagrid. my datagrid is allow shorting. i want to delete a row in the datatable. How can i know which row is deleting? many thank for your help.

  2. #2
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [02/03] Which Row is deleted

    Suppose that there is 10 row in the datatable and check the datatable.rowcount property it show you 10.
    If you delete one row then if the row get deleted then it show you 9.

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

    Re: [02/03] Which Row is deleted

    What you see in the DataGrid is a representation of the DefaultView of your table. The index of the DataGrid row corresponds directly to the index of the bound DataRowView in the table's DefaultView.
    vb Code:
    1. Dim rowIndex As Integer = myDataGrid.CurrentRowIndex
    2. Dim boundRow As DataRowView = myDataTable.DefaultView(rowIndex)
    3. Dim actualRow As DataRow = boundRow.Row
    Note also that the DataTable itself has events, so you can handle the RowDeleting and RowDeleted events of your DataTable.
    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

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    81

    Re: [02/03] Which Row is deleted

    Code:
    dim myRow as DataRow
    dim dtClone as New DataTable
    myRow = dt.Select(stFilter)
    dtClone = dt.Clone 'dt is main data table
    dgData.datasource=dtclone  'dgdata is datagrid
    when row in dtclone was added, modified or deleted, how could dt know which Row is added, modified or deleted?
    help me please?

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

    Re: [02/03] Which Row is deleted

    That code doesn't make sense. You declare myRow as type DataRow and try to assign the result of calling DataTable.Select to it, but Select returns a DataRow array, not a DataRow. You then never even use the myRow variable after that anyway, so what's it for?

    Assume that cloning people is possible. Scientists create a clone of you. How would you know if your clone did something? You wouldn't would you? Not unless you were told. The same is true here. Those DataTables have the same schema but they are not connected. They are completely independent of each other, so changes to one have no effect on the other. If you want the original table to be affected by changes to the clone then you have to make them. That begs the question why you are using a clone in the first place. If you want to know when rows are changed in a DataTable then you need to handle the appropriate events of that table. Check out the DataTable documentation to see what events it has.
    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

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    81

    Re: [02/03] Which Row is deleted

    sorry this is my copy mistake. here the full code
    Code:
    dim myRow() as DataRow
    dim dtClone as New DataTable
    dim i as integer
    myRow = dt.Select(stFilter)
    dtClone = dt.Clone 'dt is main data table
    For i = 0 To myRow.Length - 1
        dtClone.ImportRow(myRow(i))
    Next
    dgData.datasource=dtclone  'dgdata is datagrid
    actually this function do some search, that why i used clone. do you have any idea for this code please?
    I will try to find document for datatable. if you have it, would you shared it for me please?

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

    Re: [02/03] Which Row is deleted

    There's no need to do what you're doing there. Just bind the original DataTable to the grid and filter it like this:
    vb Code:
    1. dt.DefaultView.RowFilter = stFilter
    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