Jassim Rahma


I am using this code to populate data into datagridview and i want to add a simple checkbox column which is not related to any field in the database but it will be used for the staffto select the visit and make the payments for the selected visits only.

how can i do that

public void get_visits()
this.Cursor = Cursors.WaitCursor;

data_table = new DataTable();
// sql_connection = new SqlConnection("Data Source=.\\SQLEXPRESS;initial catalog=shefa;integrated security=true");
sql_connection = new SqlConnection(public_var.sql_connection);
sql_command = new SqlCommand("sp_get_patient_visits", sql_connection);
sql_command.CommandType = CommandType.StoredProcedure;
sql_command.Parameters.Add("@file_no", SqlDbType.Int).Value = file_no;
sql_adapter = new SqlDataAdapter(sql_command);
dataVisits.DataSource = data_table;

dataVisits.Columns["visit_id"].HeaderText = "insurance id";
dataVisits.Columns["visit_id"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight;
dataVisits.Columns["visit_id"].Visible = false;

dataVisits.Columns["created_date"].HeaderText = "Visit Created";
dataVisits.Columns["created_date"].DefaultCellStyle.Format = "ddd dd MMM yyyy HH:mm";
dataVisits.Columns["created_date"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter;
dataVisits.Columns["created_date"].Width = 160;

dataVisits.Columns["direct_or_insurance"].HeaderText = "Payment";
dataVisits.Columns["direct_or_insurance"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter;
dataVisits.Columns["direct_or_insurance"].Width = 120;

dataVisits.Columns["visit_total_amount"].HeaderText = "Total Amount";
dataVisits.Columns["visit_total_amount"].DefaultCellStyle.Format = "BD #,###,0.000";
dataVisits.Columns["visit_total_amount"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter;
dataVisits.Columns["visit_total_amount"].Width = 120;

dataVisits.Columns["visit_closing_paid"].HeaderText = "Paid Amount";
dataVisits.Columns["visit_closing_paid"].DefaultCellStyle.Format = "BD #,###,0.000";
dataVisits.Columns["visit_closing_paid"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter;
dataVisits.Columns["visit_closing_paid"].Width = 120;

dataVisits.Columns["visit_is_open"].HeaderText = "Open ";
dataVisits.Columns["visit_is_open"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter;
dataVisits.Columns["visit_is_open"].Width = 120;

// dataVisits.Refresh();

if (file_is_open == "N")
toolOpenCloseFile.Visible = true;
toolVitalSigns.Visible = false;
toolPayment.Visible = false;
toolOpenCloseFile.Visible = false;
toolVitalSigns.Visible = true;
toolPayment.Visible = true;

Re: Windows Forms Data Controls and Databinding how to add such checkbox column?

BabyFace Jay

Try this:

Code Snippet

DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();


Re: Windows Forms Data Controls and Databinding how to add such checkbox column?

Jassim Rahma

it's working but when selecting it dosn't select (it dosn't mark the checkbox). i tried TrueValue = true an FalseValue = false but still not working.

Re: Windows Forms Data Controls and Databinding how to add such checkbox column?

Yu Guo – MSFT

Hi, Jassim,

Do you mean that you cannot check the CheckBox or you cannot get the value of that CheckBoxes

Could you please tell us more about the business logic here

And please try the following codes to see if it works in your computer.

Code Snippet

private void Form1_Load(object sender, EventArgs e)


DataTable datatable = new DataTable();



datatable.Rows.Add("ABC", "bcd");

datatable.Rows.Add("bcd", "ABC");

dataGridView1.AutoGenerateColumns = false;

DataGridViewCheckBoxColumn checkColumn = new DataGridViewCheckBoxColumn();


DataGridViewTextBoxColumn textColumn = new DataGridViewTextBoxColumn();

textColumn.DataPropertyName = "col1";

textColumn.HeaderText = "Column1";


dataGridView1.DataSource = datatable;