Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi!

I wanna the code that get the row number of a selected cell in data grid view and the code that can select other cells in the row. :D

thank U
doostl
Posted
Updated 23-Aug-18 0:37am
Comments
[no name] 4-Sep-13 12:53pm    
So open up your code editor and write the code.
abbaspirmoradi 4-Sep-13 13:36pm    
Nobody give you code.you try and we help you....

special thanks to ridoy and others who helped

the exact code that i need and got:

C#
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
      {
        int i = 0;
        dataGridView1.Rows[dataGridView1.SelectedCells[i].RowIndex].Selected = true;
        i++;
      }
 
Share this answer
 
You need to study it and then try yourself:
How to: Get the Selected Cells, Rows, and Columns in the Windows Forms DataGridView Control[^]
Or,Use:
datagridview.CurrentCell.RowIndex

to get the row number of a selected cell.
 
Share this answer
 
v3
Comments
i.fakhari 4-Sep-13 14:54pm    
thank you
it was helpful and i got the code to get the index of selected cell but i could't find any code to select a complete row(whole cells of the row), i wonder if you could help me. :D
ridoy 4-Sep-13 15:30pm    
You can use dataGridView1.SelectedRows[0].Index to get the index of the selected row.
MsgBox(DataGridView1.Item(0, DataGridView1.CurrentCell.RowIndex).Value)
 
Share this answer
 

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