Click here to Skip to main content
13,191,642 members (64,482 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
How can i check datagridview any cell are selected or not.
Posted 28-Dec-12 0:24am
Updated 2-Jan-17 5:20am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
this.dataGridView1.Rows[0].Cells[0].Selected;//true/false
  Permalink  
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 .....
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I solve my self......

if (dataGridView1.SelectedCells.Count>0)
           {
              //True statement
           }
           else
           {
              //False statement
           }
  Permalink  
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..
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

if(dataGridview1.CurrentCell != null)
{
// DO something here
}
  Permalink  
Comments
CHill60 1-Jun-16 6:01am
   
The question is over 3 years old and already resolved. Avoid doing this
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

//check if the selected cell is at first column
if (dataGridView.CurrentCell.ColumnIndex == 0)
{
//true statement
}
else
{
//false statement
}

happy coding ;)
  Permalink  
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


Advertise | Privacy |
Web01 | 2.8.171017.2 | Last Updated 2 Jan 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100