Datagrid vs. datatable rows

G

Guest

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
 
C

Cor Ligthert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top