469,595 Members | 2,296 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,595 developers. It's quick & easy.

Datagrid vs. datatable rows

Jon
Question: does datagrid1.isSelected(i) point to the same
row as datatable.row(i).delete after datagrid sorted??
I am using datagrid1.isSelected(i) to identify datatable rows that
have been selected by the user

Then I use datatable.rows(i).delete to delete those rows.

It works fine if I have not sorted the datatable first. But if
I do sort it, then the row index identified in the
datagrid.isSelected(i) code
is not the same row deleted in the
datatable.rows(i).deleted code.

The section of code is below.
'get ids of selected rows store in array selected
For i = 1 To dt_data.Rows.Count
If DataGrid1.IsSelected(i - 1) Then
nselected += 1
selected(nselected) = i
End If
Next

'dele and transfer each selected but in reverse order
For i = nselected To 1 Step -1
' Remove row from datagrid
dt_data.Rows(selected(i) - 1).Delete()
Next i
Nov 21 '05 #1
1 4398
Jon,

Your question is one of the reasons why you can better take a dataview as
the datasource for a datagrid. (And use the currencymanager as well)

I hope this helps?

Cor

"Jon" <Jo*@discussions.microsoft.com>
Question: does datagrid1.isSelected(i) point to the same
row as datatable.row(i).delete after datagrid sorted??
I am using datagrid1.isSelected(i) to identify datatable rows that
have been selected by the user

Then I use datatable.rows(i).delete to delete those rows.

It works fine if I have not sorted the datatable first. But if
I do sort it, then the row index identified in the
datagrid.isSelected(i) code
is not the same row deleted in the
datatable.rows(i).deleted code.

The section of code is below.
'get ids of selected rows store in array selected
For i = 1 To dt_data.Rows.Count
If DataGrid1.IsSelected(i - 1) Then
nselected += 1
selected(nselected) = i
End If
Next

'dele and transfer each selected but in reverse order
For i = nselected To 1 Step -1
' Remove row from datagrid
dt_data.Rows(selected(i) - 1).Delete()
Next i

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Newbie | last post: by
5 posts views Thread by John Richardson | last post: by
4 posts views Thread by Glenn Owens | last post: by
4 posts views Thread by tshad | last post: by
8 posts views Thread by Strahimir Antoljak | last post: by
4 posts views Thread by Jan Nielsen | last post: by
3 posts views Thread by Datatable Dataset Datagrid help | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.