checkboxes in datagridview(windows application)

Reply

Join Date: Jul 2007
Posts: 29
Reputation: creativehacker is an unknown quantity at this point 
Solved Threads: 0
creativehacker creativehacker is offline Offline
Light Poster

checkboxes in datagridview(windows application)

 
0
  #1
Jan 11th, 2009
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..


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

Deleting one row...

  1. private void btnDelete_Click(object sender, EventArgs e)
  2. {
  3. if (GlobalDataStore.GetInstance().CheckedStatus == true)
  4. {
  5. string fName = GlobalDataStore.GetInstance().FirstName;
  6. string relation = GlobalDataStore.GetInstance().Relation;
  7. string idcardno = GlobalDataStore.GetInstance().Idcardno;
  8. string query = "DELETE FROM DETAIL WHERE idcard_no = '" + idcardno.Trim() + "'" + " AND FM_NAME = '" + fName.Trim() + "'" + " AND rln_fm_nm = '" + relation.Trim() + "'";
  9. DataSet ds = new DataSet();
  10. OracleDataAdapter da = new OracleDataAdapter(query, this.connection);
  11. da.Fill(ds);
  12. DataTable dt = ds.Tables[0];
  13. dt.Columns.Add("View");
  14. DataRow dr = dt.NewRow();
  15. dr["View"] = "View";
  16. dt.Rows.Add(dr);
  17. dt.AcceptChanges();
  18. DataView my_DataView = dt.DefaultView;
  19. dataGridView1.DataSource = my_DataView;
  20. connection.Close();
  21. }
  22. }

Can anyone help me with the logic...

regards
venkat
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,289
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 357
ddanbe's Avatar
ddanbe ddanbe is online now Online
Nearly a Posting Maven

Re: checkboxes in datagridview(windows application)

 
0
  #2
Jan 11th, 2009
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.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 187
LizR LizR is offline Offline
Posting Virtuoso

Re: checkboxes in datagridview(windows application)

 
0
  #3
Jan 11th, 2009
You need to look at the draw event most likely
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 46
Reputation: BlackSun is an unknown quantity at this point 
Solved Threads: 4
BlackSun BlackSun is offline Offline
Light Poster

Re: checkboxes in datagridview(windows application)

 
0
  #4
Jan 12th, 2009
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 .
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,289
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 357
ddanbe's Avatar
ddanbe ddanbe is online now Online
Nearly a Posting Maven

Re: checkboxes in datagridview(windows application)

 
0
  #5
Jan 12th, 2009
BlackSun, smoking some of those funny sigarettes again?
It's all about the DataGridView and the DataGridViewCheckBoxColumn class.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 46
Reputation: BlackSun is an unknown quantity at this point 
Solved Threads: 4
BlackSun BlackSun is offline Offline
Light Poster

Re: checkboxes in datagridview(windows application)

 
0
  #6
Jan 15th, 2009
ok man i don`t concentrate well
and i will not smoke those Cigarettes again
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum


Views: 4345 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC