PC Review


Reply
Thread Tools Rate Thread

DataGridView CheckBox Column (.NET 2.0/C#)

 
 
=?Utf-8?B?UGV0ZQ==?=
Guest
Posts: n/a
 
      15th Nov 2006
I have encountered the following issue :

I have a DataGridView control on a windows form with a checkbox column. When
the user clicks the column header, I need to toggle the selected state of the
checkboxes...basically a 'select/deselect all'.

Everything is working fine, except the checkbox in the very first row does
not show the check mark unless i actually click the control itself. rows 1
thru n work fine. I have verified that the value is being set on the first
row's checkbox, so it seems to be a display issue. Here is the code:

void grdDirectReports_ColumnHeaderMouseClick(object sender,
DataGridViewCellMouseEventArgs e)
{

DataGridView dgv = (DataGridView)sender;

if (e.ColumnIndex == dgv.Columns["Selected"].Index)
{
if (e.RowIndex < 0)
{
for (int i = 1; i < dgv.Rows.Count; i++)
{
dgv.Rows[i].Cells[0].Value =
!lastDRGridCheckAllSelected;
}
lastDRGridCheckAllSelected = !lastDRGridCheckAllSelected;

dgv.Refresh();
}
}
}

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=
Guest
Posts: n/a
 
      15th Nov 2006
You are starting at row 1 instead of row 0 in your for loop, try this:
void grdDirectReports_ColumnHeaderMouseClick(object sender,
DataGridViewCellMouseEventArgs e)
{

DataGridView dgv = (DataGridView)sender;

if (e.ColumnIndex == dgv.Columns["Selected"].Index)
{
if (e.RowIndex < 0)
{
for (int i = 0; i < dgv.Rows.Count; i++)
{
dgv.Rows[i].Cells[0].Value =
!lastDRGridCheckAllSelected;
}
lastDRGridCheckAllSelected = !lastDRGridCheckAllSelected;

dgv.Refresh();
}
}
}


"Pete" wrote:

> I have encountered the following issue :
>
> I have a DataGridView control on a windows form with a checkbox column. When
> the user clicks the column header, I need to toggle the selected state of the
> checkboxes...basically a 'select/deselect all'.
>
> Everything is working fine, except the checkbox in the very first row does
> not show the check mark unless i actually click the control itself. rows 1
> thru n work fine. I have verified that the value is being set on the first
> row's checkbox, so it seems to be a display issue. Here is the code:
>
> void grdDirectReports_ColumnHeaderMouseClick(object sender,
> DataGridViewCellMouseEventArgs e)
> {
>
> DataGridView dgv = (DataGridView)sender;
>
> if (e.ColumnIndex == dgv.Columns["Selected"].Index)
> {
> if (e.RowIndex < 0)
> {
> for (int i = 1; i < dgv.Rows.Count; i++)
> {
> dgv.Rows[i].Cells[0].Value =
> !lastDRGridCheckAllSelected;
> }
> lastDRGridCheckAllSelected = !lastDRGridCheckAllSelected;
>
> dgv.Refresh();
> }
> }
> }
>

 
Reply With Quote
 
New Member
Join Date: Sep 2011
Posts: 1
 
      19th Sep 2011
Hello Everyone,
For complete information about datagrdiview checkbox using c#, you may check out the following links!!!!!

http://mindstick.com/Articles/77b73d...20DataGridView

Thanks !!!!
 
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 and checkbox column Bhavin Parekh Microsoft C# .NET 2 17th Nov 2009 12:58 AM
DataGridView checkbox column issue Marco Pais Microsoft C# .NET 1 3rd Apr 2008 12:51 PM
How to Add *AND* Process Checkbox Column in a DataGridView? Hexman Microsoft VB .NET 4 11th Dec 2006 01:04 AM
DataGridView Column Header text with Checkbox. cooltami@gmail.com Microsoft Dot NET Framework 0 6th Oct 2006 05:06 PM
Select-All Checkbox in a Column Header of DataGridView =?Utf-8?B?U3lC?= Microsoft VB .NET 0 13th Jul 2006 01:53 AM


Features
 

Advertising
 

Newsgroups
 


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