473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

datagridview.SelectedRows returns last row first?

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

Sep 5 '06 #1
2 13797
On 5 Sep 2006 08:23:32 -0700, "Nickneem" <ni******@gmail.comwrote:
>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(DataGridViewElem entStates.Selected)
If SelectedRowCount 0 Then
For i As Integer = SelectedRowCount - 1 To 0 Step -1
MsgBox(DataGridView1.SelectedRows(i).Cells(1).Valu e.ToString)

Next
End If

Gene
Sep 6 '06 #2

gene kelley wrote:
On 5 Sep 2006 08:23:32 -0700, "Nickneem" <ni******@gmail.comwrote:
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(DataGridViewElem entStates.Selected)
If SelectedRowCount 0 Then
For i As Integer = SelectedRowCount - 1 To 0 Step -1
MsgBox(DataGridView1.SelectedRows(i).Cells(1).Valu e.ToString)

Next
End If

Gene
Works great Gene, thanks a lot!!

Kind regards,

Mike

Sep 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ye Li | last post by:
I have two windows with datagridview control type in one form. I want to move multiple rows from one datagridview to another datagridview. My code is as follows: private void...
2
by: Rich | last post by:
Hello, Some database applicatins have a tooltip feature where when you are dragging the scrollbar of the table view a tooltip appears next to the mouse cursor displaying the approximate record...
4
by: Annie | last post by:
hello guys, I am having a DataGridView control. The first column is a checkbox column. The users can select the checkbox column. I need to loop through the grid rows and get the checked...
9
by: trint | last post by:
How can I retrieve all of the data from a datagridview? Any help is appreciated. Thanks, Trint
1
by: jed | last post by:
Hello i need help on this i have read data into a gridview using sql statement. string loadCustomer = "SELECT * FROM Customers"; OleDbDataAdapter dataAdapter = new...
20
by: Phil | last post by:
VB2008 I have a DataGridView with MultiSelect = True and SelectionMode=FullRowSelect. One of the columns is a checkbox column. I have a function that goes through all the selected rows and sets...
1
by: Aegixx | last post by:
Ok, extremely wierd situation here: (I'll post the code below, after the explanation) I've got a Windows application (.NET 3.5) that has a single Form with a DataGridView embedded. The user...
0
by: cday119 | last post by:
Hi All, I have a datagridview, and I'm looping threw the selected rows like so: For Each row As System.Windows.Forms.DataGridViewRow In OrderDataGridView.SelectedRows This DataGridView Holds...
2
by: cday119 | last post by:
Hi Everyone, So I have a datagridview and it has a column called status. It has 3 values: New, Printed, and Shipped. Now a user can select multiple rows and click "set to printed". I then do...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.