Thursday, 18 October 2012

add checkbox in DataGridView in windows c#.net

 dataGridView1.ColumnCount = 2;
            dataGridView1.Columns[0].Name = "EID";
            dataGridView1.Columns[1].Name = "NAME";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string[] r = new string[] { dt.Rows[i].ItemArray[0].ToString(), dt.Rows[i].ItemArray[1].ToString() };
                dataGridView1.Rows.Add(r);
            }
            DataGridViewCheckBoxColumn dgc = new DataGridViewCheckBoxColumn();
            dgc.HeaderText = "Click";
            dataGridView1.Columns.Add(dgc);
           
        }
        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[2].Value) == true)
                    MessageBox.Show(dataGridView1.Rows[i].Cells[2].Value.ToString());
                else
                    MessageBox.Show("False");
        }

No comments:

Post a Comment