|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
datagridview.SelectedRows returns last row first?stepping through the selectedrows because the first row I get is the last row selected (with the heighest index). For instance if I select 3 rows jan feb mar Dim TmpRow As DataGridViewRow For Each TmpRow In dgReports.SelectedRows msgbox tmprow.index next tmprow I'll get 3,2,1 instead of 1,2,3 I don't know if this is by design but it gives me a hard time doing my stuff right... Thanks in advance, Mike
Show quote
Hide quote
On 5 Sep 2006 08:23:32 -0700, "Nickneem" <nickn***@gmail.com> wrote: Apparently LIFO (last in, first out) by design.>I'm trying to figure out the datagridview, but I'm having trouble >stepping through the selectedrows because the first row I get is the >last row selected (with the heighest index). > >For instance if I select 3 rows >jan >feb >mar > >Dim TmpRow As DataGridViewRow >For Each TmpRow In dgReports.SelectedRows > msgbox tmprow.index >next tmprow > >I'll get 3,2,1 instead of 1,2,3 > >I don't know if this is by design but it gives me a hard time doing my >stuff right... > >Thanks in advance, > >Mike You can do this: Dim SelectedRowCount As Integer = _ Me.DataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected) If SelectedRowCount > 0 Then For i As Integer = SelectedRowCount - 1 To 0 Step -1 MsgBox(DataGridView1.SelectedRows(i).Cells(1).Value.ToString) Next End If Gene gene kelley wrote:
Show quoteHide quote > On 5 Sep 2006 08:23:32 -0700, "Nickneem" <nickn***@gmail.com> wrote: Works great Gene, thanks a lot!!> > >I'm trying to figure out the datagridview, but I'm having trouble > >stepping through the selectedrows because the first row I get is the > >last row selected (with the heighest index). > > > >For instance if I select 3 rows > >jan > >feb > >mar > > > >Dim TmpRow As DataGridViewRow > >For Each TmpRow In dgReports.SelectedRows > > msgbox tmprow.index > >next tmprow > > > >I'll get 3,2,1 instead of 1,2,3 > > > >I don't know if this is by design but it gives me a hard time doing my > >stuff right... > > > >Thanks in advance, > > > >Mike > > Apparently LIFO (last in, first out) by design. > > You can do this: > Dim SelectedRowCount As Integer = _ > Me.DataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected) > If SelectedRowCount > 0 Then > For i As Integer = SelectedRowCount - 1 To 0 Step -1 > MsgBox(DataGridView1.SelectedRows(i).Cells(1).Value.ToString) > > Next > End If > > Gene Kind regards, Mike
Help with Adding A Row
is an object destroyed/closed when an exception occurs How to input characters that are not present in a keyboard to a VB User Control constructors taking arguments? source and multiple machines newbe help please. paste disabled when i add a menubar in vb2005 UI Challenge: How to create a real outliner (like Ecco, Grandview, etc) - SampleDisplay.bmp (0/1) Book Recommendations Request Windows form is getting crashed VB.Net 2005 Break up string, Comma Delimited |
|||||||||||||||||||||||