|
-
May 1st, 2007, 01:28 AM
#1
Thread Starter
Lively Member
[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.
-
May 1st, 2007, 02:00 AM
#2
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.
-
May 1st, 2007, 02:06 AM
#3
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:
Dim rowIndex As Integer = myDataGrid.CurrentRowIndex
Dim boundRow As DataRowView = myDataTable.DefaultView(rowIndex)
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.
-
May 3rd, 2007, 10:15 PM
#4
Thread Starter
Lively Member
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?
-
May 3rd, 2007, 11:10 PM
#5
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.
-
May 3rd, 2007, 11:46 PM
#6
Thread Starter
Lively Member
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?
-
May 4th, 2007, 12:03 AM
#7
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:
dt.DefaultView.RowFilter = stFilter
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
|