C#Net2003 - Add CheckBox in DataGrid

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2006
Posts: 26
Reputation: LennieKuah is an unknown quantity at this point 
Solved Threads: 0
LennieKuah LennieKuah is offline Offline
Light Poster
 
0
  #11
22 Days Ago
Hi Vinnijian,
DateGrid is only in C#.Net 2003 while DataGridView is in C#.Net 2005.

In C#Net, the DataGrid property does not have item COLUMN.

Not all the scripts in C#.Net 2005 is applicable in C#.Net 2003. Please help me with script for C#.Net 2003. Thank you very much.
Last edited by LennieKuah; 22 Days Ago at 3:42 pm.
Have a Good Day.

Cheers,
Lennie
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 26
Reputation: LennieKuah is an unknown quantity at this point 
Solved Threads: 0
LennieKuah LennieKuah is offline Offline
Light Poster
 
0
  #12
16 Days Ago
Hi Vinnijian and All Helpers
Yeee...Haa.......Finally I got the script working. Thanks to you guys for sharing your knowledge with me. You guys and this FORUM are awesome


I would like to post the script here to share with newbie like me facing the same problems:

  1. private void FLoadDataGrid()
  2. {
  3. try
  4. {
  5. string strSql = "Select FirstName, LastName from TblCustomer ";
  6. sqlConn = new SqlConnection(connStr);
  7. sqlConn.Open();
  8. DA = new SqlDataAdapter(strSql, sqlConn);
  9. DS = new DataSet("DS");
  10.  
  11. //Clear dataset before refill
  12. DS.Clear();
  13. DS.CaseSensitive = true;
  14. DA.Fill(DS,"PatientTbl");
  15.  
  16. //declare datatable
  17. DataTable DT = new DataTable();
  18. DT.Clear();
  19. DT = DS.Tables[0];
  20.  
  21. DataColumn colNewDGCol = new DataColumn();
  22. colNewDGCol.DataType = System.Type.GetType("System.Boolean");
  23. colNewDGCol.DefaultValue = false;
  24. colNewDGCol.ColumnName = ("Selected");
  25. DT.Columns.Add(colNewDGCol);
  26.  
  27. //... file datagrid
  28. FFormatDataGridColumn();
  29. dataGrid1.DataSource = DT;
  30. }
  31. catch (Exception Ex)
  32. {
  33. MessageBox.show(Ex.Message);
  34. }
  35. finally
  36. {
  37. sqlConn.Close();
  38. }
  39. }
/* ------------------------------------------------------------------ */
  1. private void FFormatDataGridColumn()
  2. //define column structure for datagrid
  3. {
  4. // declare tablestyle
  5. DataGridTableStyle DGStyle;
  6. DGStyle = new DataGridTableStyle();
  7. DGStyle.MappingName = "PatientTbl";
  8.  
  9. //checkbox column
  10. DataGridBoolColumn chkboxCol = new DataGridBoolColumn();
  11. chkboxCol.MappingName = "Selected";
  12. chkboxCol.HeaderText = "";
  13. chkboxCol.Width = 50;
  14. DGStyle.GridColumnStyles.Add(chkboxCol);
  15.  
  16. //Firstname textbox column
  17. DataGridColumnStyle colFName = new DataGridTextBoxColumn();
  18. colFName.MappingName = "FirstName";
  19. colFName.HeaderText = "First Name";
  20. colFName.Width = 150;
  21. DGStyle.GridColumnStyles.Add(colFName);
  22.  
  23. //lastName textbox column
  24. DataGridColumnStyle colLName = new DataGridTextBoxColumn();
  25. colLName.MappingName = "LastName";
  26. colLName.HeaderText = "Last Name";
  27. colLName.Width = 150;
  28. DGStyle.GridColumnStyles.Add(colLName);
  29.  
  30. // add table style to the dataGrid
  31. this.dataGrid1.TableStyles.Add(DGStyle);
  32. }


THANKS TO ALL OF YOU.
Have a Good Day.

Cheers,
Lennie
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC