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.
Printable View
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.
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.
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.Note also that the DataTable itself has events, so you can handle the RowDeleting and RowDeleted events of your DataTable.vb Code:
Dim rowIndex As Integer = myDataGrid.CurrentRowIndex Dim boundRow As DataRowView = myDataTable.DefaultView(rowIndex) Dim actualRow As DataRow = boundRow.Row
when row in dtclone was added, modified or deleted, how could dt know which Row is added, modified or 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
help me please?
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.
sorry this is my copy mistake. here the full code
actually this function do some search, that why i used clone. do you have any idea for this code please?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
I will try to find document for datatable. if you have it, would you shared it for me please?
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