[RESOLVED] Multiple rows selection problem
I've got a little problem i haven't being able to solve.
see screenhot here http://justanotherhomepage.net/3rowsselected.jpg
I use this sub to browse thru the selected rows of the datagrid
VB Code:
Dim lista As New ArrayList
lista = GetSelectedRows(Me.DataGrid2)
For i = 0 To lista.Count - 1
ind = Convert.ToInt32(lista(i))
Me.DataGrid2.Select(ind)
genc = Me.DataGrid2.Item(Me.DataGrid2.CurrentRowIndex, 0).ToString
gposenc = Convert.ToInt32(Me.DataGrid2.Item(Me.DataGrid2.CurrentRowIndex, 1))
Console.WriteLine("index=" & ind.ToString)
Console.WriteLine("enc=" & genc)
Console.WriteLine("posenc=" & gposenc.ToString)
Next
the console.write outoput is
index=34
enc=741/99
posenc=5
index=36
enc=741/99
posenc=5
index=38
enc=741/99
posenc=5
It should be
index=34
enc=741/99
posenc=1
index=36
enc=741/99
posenc=3
index=38
enc=741/99
posenc=5
VB Code:
Private Function GetSelectedRows(ByVal dg As DataGrid) As System.Collections.ArrayList
Dim al As New ArrayList
Dim cm As CurrencyManager = DirectCast(Me.BindingContext(dg.DataSource, dg.DataMember), CurrencyManager)
Dim dv As DataView = CType(cm.List, DataView)
Dim i As Integer
For i = 0 To dv.Count - 1
If dg.IsSelected(i) Then
al.Add(i)
End If
Next
Return al
End Function 'GetSelectedRows
Regards
Jorge
Re: Multiple rows selection problem
You're using the CurrentRowIndex property to get your values. The CurrentRowIndex corresponds to the row with the arrow icon in the left hand margin. It looks like your "ind" variable is the one that contains the row index so you should be using that. Also, I'd suggest that your GetSelectedRows method return an Integer array, which is more appropriate given that it contains Integers, which must be boxed in an ArrayList.
Re: Multiple rows selection problem
Thanks jmcilhinney, you pointed me in the right direction , its working now as expected.
Regards
Jorge