Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i wanna get row numbers selected rows in datagridview.
plz guide me ...
Posted

First you show do this;
C#
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

this way users will select the full row instead of the cells. then you can have the selected rows by an foreach loop.

C#
foreach (DataGridViewRow r in dataGridView1.SelectedRows)
{
  // do stuff
}

-OR-
2nd way
Check the MSDN selected row link[^]
Good luck
 
Share this answer
 
v2
Try Link[^]
 
Share this answer
 
refer this link

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectedrows.aspx[^]

you can also try this

C#
private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow currentRow = dataGridView1.SelectedRows;

            ID = Convert.ToInt32(currentRow.Cells[0].Value);
            textBox1.Text = Convert.ToString(currentRow.Cells[1].Value);
           }

        }
 
Share this answer
 
v2
 
Share this answer
 
Comments
Orcun Iyigun 28-Sep-11 3:34am    
The OP tagged it as C#, your answer link explains it in ASP.Net and it is not answering his question fully.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900