checkbox in datagrid

checkbox status in datagrid

Page 1 of 1

1 Replies - 3678 Views - Last Post: 17 February 2009 - 07:12 AM Rate Topic: -----

#1 pnvreddy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-February 09

checkbox in datagrid

Post icon  Posted 17 February 2009 - 04:59 AM

if we un check the checkbox the datagrid the count should be decreased , but i am not getting that one please help me




private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 8; i++)
dataGridView1.Rows.Add();
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
for (int x = 0; x <= 8; x++)
{
if (dataGridView1[0, x].Selected == true)
{
count++;

if (dataGridView1[0, x].Selected == false)
{
count--;
}

if (count > 3)
{
MessageBox.Show("checked");
}

}
}
}

Is This A Good Question/Topic? 0
  • +

Replies To: checkbox in datagrid

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: checkbox in datagrid

Posted 17 February 2009 - 07:12 AM

You have the test for false nested inside the test for true... it will never be false! :)
if (dataGridView1[0, x].Selected == true)
{
	count++;

	if (dataGridView1[0, x].Selected == false)
...


Try this instead
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
	int count = 0;
	
	for (int x = 0; x <= 8; x++)
	{
		if (dataGridView1[0, x].Selected == true)
			count++;
		else
			count--;
	}

	if (count > 3)
		MessageBox.Show("checked");
}	   


This post has been edited by n8wxs: 17 February 2009 - 07:17 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1