I am adding checkbox to datagridview.
how can I add a checkbox to the header so that when I click that all the checkboxes should be checked and corresponding rows should be deleted.. I am able to delete one row at a time. How to delete multiple rows..

DataGridViewCheckBoxColumn chkBoxColumn = new DataGridViewCheckBoxColumn();
              chkBoxColumn.Name = "CheckBoxes";
dataGridView1.Columns.Add(chkBoxColumn);

Deleting one row...

private void btnDelete_Click(object sender, EventArgs e)
        {
            if (GlobalDataStore.GetInstance().CheckedStatus == true)
            {
              string fName = GlobalDataStore.GetInstance().FirstName;
              string relation = GlobalDataStore.GetInstance().Relation;
              string idcardno = GlobalDataStore.GetInstance().Idcardno;
               string query = "DELETE  FROM DETAIL WHERE idcard_no = '" + idcardno.Trim() + "'" + " AND  FM_NAME = '" + fName.Trim() + "'" + " AND rln_fm_nm = '" + relation.Trim() + "'";
             DataSet ds = new DataSet();
             OracleDataAdapter da = new OracleDataAdapter(query, this.connection);
             da.Fill(ds);
             DataTable dt = ds.Tables[0];
             dt.Columns.Add("View");
             DataRow dr = dt.NewRow();
             dr["View"] = "View";
             dt.Rows.Add(dr);
             dt.AcceptChanges();
             DataView my_DataView = dt.DefaultView;
             dataGridView1.DataSource = my_DataView;
             connection.Close();
            }
          }

Can anyone help me with the logic...

regards
venkat

Recommended Answers

All 5 Replies

Some hints perhaps on how I would start to handle this problem:
Use the properties SelectedCells, SelectedColumns, SelectedRows and SelectionMode.
Make also use of the event MultiSelectChanged.
Example : Select the checkbox column, change one checkbox in it and change all the others in your code accordingly.
I have not worked this out, but if I would have to do this, this is what I should try. Hope it helps.

You need to look at the draw event most likely

hi
sorry amn`t finish ur problem yet but u can use this :

CheckBox ck = new CheckBox();
ck.BackColor = Color.Transparent;
dataGridView1.Controls.Add(ck);

the u can do algorithm which u can put ur checkbox in ur certain header and do ur conditions .... after returning back i will do it .

BlackSun, smoking some of those funny sigarettes again?
It's all about the DataGridView and the DataGridViewCheckBoxColumn class.

ok man i don`t concentrate well :D
and i will not smoke those Cigarettes again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.