Click here to Skip to main content
12,634,888 members (27,580 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# .NET C#4.0 .NET4
How can i check datagridview any cell are selected or not.
Posted 28-Dec-12 1:24am
Updated 31-May-16 23:36pm
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 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 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..

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 | Mobile
Web02 | 2.8.161208.2 | Last Updated 1 Jun 2016
Copyright © CodeProject, 1999-2016
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