Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How can i check datagridview any cell are selected or not.
Posted
Updated 2-Jan-17 5:20am

DataGridView has a property Called SelectedCells which returns the collection of cells selected by the user.

or you can check the Selected Property of cell like below
C#
this.dataGridView1.Rows[0].Cells[0].Selected;//true/false
 
Share this answer
 
v2
Comments
Shambhoo kumar 28-Dec-12 7:47am    
this is not my question answer dear..my exact question is "Whenever i click a button then check on that time grid cell are selected or not".
Jibesh 28-Dec-12 7:57am    
The solution is for what you put in as a question.

if you are expecting something different then your question needs to be more specific so that you can get a better and more apt solution for your query.

you mean you want to select a cell programaticaly?
Shambhoo kumar 28-Dec-12 7:59am    
not select cell i want to know Gridview any cell status "selected or not ".
Jibesh 28-Dec-12 8:06am    
you can still get that using the SelectedCells collection. If collection is empty no cells are selected. or by using Cell.Selected property. check my updated solution.
Shambhoo kumar 28-Dec-12 12:03pm    
your code is also good sir but this code is only apply when grid first row of first column selected. but i don't want these .....
I solve my self......

SQL
if (dataGridView1.SelectedCells.Count>0)
           {
              //True statement
           }
           else
           {
              //False statement
           }
 
Share this answer
 
Comments
Jibesh 28-Dec-12 13:35pm    
what difference you found in this solution with my solution??
Shambhoo kumar 29-Dec-12 3:24am    
Because Your solution only run when i select First row of first cell. but when i select Another cell then ur code is not working..
if(dataGridview1.CurrentCell != null)
{
// DO something here
}
 
Share this answer
 
Comments
CHill60 1-Jun-16 6:01am    
The question is over 3 years old and already resolved. Avoid doing this
//check if the selected cell is at first column
if (dataGridView.CurrentCell.ColumnIndex == 0)
{
//true statement
}
else
{
//false statement
}

happy coding ;)
 
Share this answer
 
v2
Comments
Shambhoo kumar 5-Jan-17 0:38am    
Dear brother kindly check question post date before writing your answer. do you think still this question is not resolved?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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