Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Working of Check Box in DataGridView.
 

Working of Check Box in DataGridView.

Hi., All

I am building an applicaion in which a DataGridView is used, but i need a CheckBox in the DataGridView as first column, and a button is used.

In front of everyCheckBox there is a Customer name and as i click the button all the customer names which are checked are to entered in the different table of DataBase.

How to do this..please help me..

Is there any option to add a CheckBox in the DataGridView ?

Vishie  Saturday, July 25, 2009 8:06 AM
Hi Vishie,

DataGridView auto show CheckBox for bool column. So the easiest way to implement this is add a bool column to the underline datasource.
For example:
public partial class Form1 : Form
{
private DataTable dtCustomer;

public Form1()
{
InitializeComponent();
dtCustomer = new DataTable();
dtCustomer.Columns.Add("Name", typeof(string));
dtCustomer.Columns.Add("Checked", typeof(bool));

dtCustomer.Rows.Add("John", true);
dtCustomer.Rows.Add("Jack", false);
dtCustomer.Rows.Add("Mick", true);

dataGridView1.DataSource = dtCustomer;
}
}

When you click the button to save checked customer information, you can loop through the dtCustomer to check if the value is True, only update the row whose Checked value is true.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Tuesday, July 28, 2009 3:15 AM
Hi Vishie,

DataGridView auto show CheckBox for bool column. So the easiest way to implement this is add a bool column to the underline datasource.
For example:
public partial class Form1 : Form
{
private DataTable dtCustomer;

public Form1()
{
InitializeComponent();
dtCustomer = new DataTable();
dtCustomer.Columns.Add("Name", typeof(string));
dtCustomer.Columns.Add("Checked", typeof(bool));

dtCustomer.Rows.Add("John", true);
dtCustomer.Rows.Add("Jack", false);
dtCustomer.Rows.Add("Mick", true);

dataGridView1.DataSource = dtCustomer;
}
}

When you click the button to save checked customer information, you can loop through the dtCustomer to check if the value is True, only update the row whose Checked value is true.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Tuesday, July 28, 2009 3:15 AM

You can use google to search for other answers

Custom Search

More Threads

• Multi-part question in regards to functionality
• Install webservices on remote network server
• Problem with scrollbars of panel in C#
• FotoVision Navigation Images
• Terrarium 1.2 not showing any text on buttons?
• Errors installing Server (System.IO.FileNotFoundException)
• Taskvision Installation - The parameter is incorrect
• IssueVision for .NET 2.0 on Windowsforms.NET?
• Unable to receive creatures and unable to load local creatures
• How to specify the Colorful cursor