PC Review


Reply
Thread Tools Rate Thread

DataGridView checkbox scan?

 
 
Kim
Guest
Posts: n/a
 
      2nd Jul 2008
foreach (DataGridViewRow row in this.dataGridView.Rows)
{

if (row.Cells[0].Value.ToString() == "true")
{
return true;

}
}
return false;


I try in a if senctens to scan a datagridview cell but how to test the
checkbox cell I have look for som in books an on the inetenet but not found
somehing.

Best regard
Kim
 
Reply With Quote
 
 
 
 
Greg
Guest
Posts: n/a
 
      3rd Jul 2008
On Jul 2, 4:16*am, Kim <K...@discussions.microsoft.com> wrote:
> * * * *foreach (DataGridViewRow row in this.dataGridView.Rows)
> * * * *{
>
> * * * * * * * * if (row.Cells[0].Value.ToString() == "true")
> * * * * * * * * {
> * * * * * * * * * *return true;
>
> * * * * * * * * }
> * * * *}
> return false;
>
> I try in a if senctens to scan a datagridview cell but how to test the
> checkbox cell I have look for som in books an on the inetenet but not found
> somehing.
>
> Best regard
> Kim


Verify that the cell is of type DataGridViewCheckBoxCell first...
You also might want to verify that the
DataGridViewCheckBoxCell.TrueValue is not null since it's an object
and not a boolean data type.

foreach (DataGridViewRow row in dataGridView.Rows)
{
if (!row.IsNewRow)
{
if (row.Cells[0].GetType() ==
typeof(DataGridViewCheckBoxCell))
{
if ((bool)
(((DataGridViewCheckBoxCell)row.Cells[0]).TrueValue))
{
return true;
}
}
}
}



Cheers
Greg


 
Reply With Quote
 
Kim
Guest
Posts: n/a
 
      3rd Jul 2008


"Greg" wrote:

> On Jul 2, 4:16 am, Kim <K...@discussions.microsoft.com> wrote:
> > foreach (DataGridViewRow row in this.dataGridView.Rows)
> > {
> >
> > if (row.Cells[0].Value.ToString() == "true")
> > {
> > return true;
> >
> > }
> > }
> > return false;
> >
> > I try in a if senctens to scan a datagridview cell but how to test the
> > checkbox cell I have look for som in books an on the inetenet but not found
> > somehing.
> >
> > Best regard
> > Kim

>
> Verify that the cell is of type DataGridViewCheckBoxCell first...
> You also might want to verify that the
> DataGridViewCheckBoxCell.TrueValue is not null since it's an object
> and not a boolean data type.
>
> foreach (DataGridViewRow row in dataGridView.Rows)
> {
> if (!row.IsNewRow)
> {
> if (row.Cells[0].GetType() ==
> typeof(DataGridViewCheckBoxCell))
> {
> if ((bool)
> (((DataGridViewCheckBoxCell)row.Cells[0]).TrueValue))
> {
> return true;
> }
> }
> }
> }
>
>
>
> Cheers
> Greg
>
> Tanks but I just cast by (bool)row.Cells[0].Value == true for the cell
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGridView checkbox. Mr. X. Microsoft VB .NET 4 25th Jun 2010 08:01 AM
Datagridview checkbox Cdude Microsoft C# .NET 3 30th Apr 2010 07:16 PM
datagridview checkbox mrstrong Microsoft C# .NET 2 24th Sep 2007 02:55 AM
datagridview checkbox mrstrong Microsoft Dot NET Framework Forms 6 13th Sep 2007 12:35 AM
datagridview checkbox mrstrong Microsoft Dot NET 0 7th Sep 2007 04:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:45 AM.