944,172 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 1882
  • C# RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Nov 3rd, 2009
0
Re: C#Net2003 - Add CheckBox in DataGrid
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; Nov 3rd, 2009 at 3:42 pm.
Reputation Points: 10
Solved Threads: 0
Light Poster
LennieKuah is offline Offline
47 posts
since Mar 2006
Nov 10th, 2009
0
Re: C#Net2003 - Add CheckBox in DataGrid
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:

C# Syntax (Toggle Plain Text)
  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. }
/* ------------------------------------------------------------------ */
C# Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Light Poster
LennieKuah is offline Offline
47 posts
since Mar 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: C# Maximized Forms Are Still Movable And resizeable
Next Thread in C# Forum Timeline: Where Can I get a C# Compiler





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC