Datagridview.selectedRows

  • Thread starter Thread starter friend
  • Start date Start date
F

friend

Hello all,

for eg: I have the following in datagridview ( this i import from
excel)

1,23457E+13 ABCD1234 08.04.2009 100
1,23457E+13 ABCD1235 09.04.2009 2
1,23457E+13 ABCD1236 10.04.2009 4543
1,23457E+13 ABCD1237 11.04.2009 45
1,23457E+13 ABCD1238 12.04.2009 555
1,23457E+13 ABCD1239 13.04.2009 62

and i select some rows (during run time ) from this datagridveiw using
datagridview.selectedrows.

if i select last 3 lines from bottom to top then the output will be in
this way

1,23457E+13 ABCD1239 13.04.2009 62 (first)
1,23457E+13 ABCD1238 12.04.2009 555 (next)
1,23457E+13 ABCD1237 11.04.2009 45 (last)

I need to print in the order they are in this datagridview even they
are selected from top to bottom or in reverse.

I did in the following way :

For Each dr1 As DataGridViewRow In Me.DataGridView1.SelectedRows

For Each s2 As DataGridViewCell In dr1.Cells
readArray(s2.ColumnIndex) = s2.Value.ToString
Next
Next

Please help me ....Thanks for any help...
 
Create a sorted list of the selected row indexes and use that to select the rows in order:
Dim myList As List(Of Integer)
For Each dr1 As DataGridViewRow In Me.DataGridView1.SelectedRows
myList.Add(dr1.Index)
Next
myList.Sort()
For Each nItem As Integer In myList
Dim dr1 As DataGridViewRow = Me.DataGridView1.Rows(nItem)
For Each s2 As DataGridViewCell In dr1.Cells
readArray(s2.ColumnIndex) = s2.Value.ToString
Next
Next
 
Did you try the suggestion from the last time you posted this question?
What was the result?
 
Did you try the suggestion from the last time you posted this question?
What was the result?

The code is not working..Still it prints in the same way as I
mentioned.
 
Back
Top