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

C#Net2003 - Add CheckBox in DataGrid

 
0
  #1
26 Days Ago
Hi there,
Please help me. I am having problem trying to include Checkbox in 1st Column in DataGrid for all the Rows. Being a newbie and I am struggling doing it. I need your help.
Have a Good Day.

Cheers,
Lennie
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 45
Reputation: chandru7 is an unknown quantity at this point 
Solved Threads: 8
chandru7 chandru7 is offline Offline
Light Poster
 
0
  #2
25 Days Ago
Just Create OneTemplatecolumn like
<Columns>,in item template add one checkbox
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 117
Reputation: vinnijain is an unknown quantity at this point 
Solved Threads: 10
vinnijain vinnijain is offline Offline
Junior Poster
 
0
  #3
25 Days Ago
Originally Posted by LennieKuah View Post
Hi there,
Please help me. I am having problem trying to include Checkbox in 1st Column in DataGrid for all the Rows. Being a newbie and I am struggling doing it. I need your help.


You have to use tablestyles while binding the data to grid,
Create DataGridColumnStyle for each column.
for first column if u need check box follow this code.

  1. DataGridTableStyle tblstyle = new DataGridTableStyle();
  2. DataGridBoolColumn chkboxCol=new DataGridBoolColumn();
  3. discontinuedCol.MappingName = "chkbox";
  4. discontinuedCol.HeaderText = "";
  5. discontinuedCol.Width = 30;
  6. chkboxCol.AllowNull = false;
  7. tblstyle .GridColumnStyles.Add(chkboxCol);


Hope it helps..............
Last edited by vinnijain; 25 Days Ago at 5:35 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 117
Reputation: vinnijain is an unknown quantity at this point 
Solved Threads: 10
vinnijain vinnijain is offline Offline
Junior Poster
 
0
  #4
25 Days Ago
You can also read the article in following link:
http://www.dotnetspark.com/kb/151-ad...w-windows.aspx
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
  #5
25 Days Ago
Hi Vinnijain

C#.NET 2003 - Window Application.

I have tried out your suggestion and here is my overall script to add CheckBox into First Column and in every row in the DataGrid.

On compilation I got this error message:-The type or namespace name 'discontinuedCol' could not be found (are you missing a using directive or an assembly reference?)

Sample Script:-
  1. private void FFormatDataGridColumn()
  2.  
  3. {
  4. DataGridTableStyle DGTStyle = new DataGridTableStyle();
  5. DGTStyle.MappingName = "CustomerTbl";
  6. CheckBox chkbox = new CheckBox();
  7.  
  8. // 1st column checkbox
  9. DataGridBoolColumn chkboxCol = new DataGridBoolColumn();
  10. discontinuedCol.MappingName = "chkbox" ;
  11. discontinuedCol.HeaderText = "Select";
  12. discontinuedCol.Width = 30;
  13. discontinuedCol.AllowNull = false;
  14.  
  15. //column 2
  16. DataGridColumnStyle DGTcol2 = new DataGridTextBoxColumn();
  17. DGTcol2.MappingName = "CustID";
  18. DGTcol2.HeaderText ="Customer ID";
  19. DGTcol2.Width =50;
  20.  
  21. //column 3
  22. DataGridColumnStyle DGTcol3 = new DataGridTextBoxColumn();
  23. DGTcol3.MappingName = "FirstName";
  24. DGTcol3.HeaderText = "First NameAA";
  25. DGTcol3.Width =150;
  26.  
  27. //column 4
  28. DataGridColumnStyle DGTcol4 = new DataGridTextBoxColumn();
  29. DGTcol4.MappingName = "LastName";
  30. DGTcol4.HeaderText = "Last NameBB";
  31. DGTcol4.Width = 150;
  32.  
  33. //add column to DGTStyle
  34. DGTStyle.GridColumnStyles.Add(chkboxCol);
  35. DGTStyle.GridColumnStyles.Add(DGTcol2);
  36. DGTStyle.GridColumnStyles.Add(DGTcol3);
  37. DGTStyle.GridColumnStyles.Add(DGTcol4);
  38.  
  39.  
  40. dataGrid1.TableStyles.Add(DGTStyle);
  41.  
  42. }
Last edited by peter_budo; 24 Days Ago at 4:12 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Have a Good Day.

Cheers,
Lennie
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 117
Reputation: vinnijain is an unknown quantity at this point 
Solved Threads: 10
vinnijain vinnijain is offline Offline
Junior Poster
 
0
  #6
25 Days Ago
Add the following line in your code:

  1. DataGridBoolColumn discontinuedCol=new DataGridBoolColumn();
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
  #7
25 Days Ago
Hi Vinnijian,
I have change the script as per below based on your suggestion. The DataGrid does displays the row of data but it's without the CheckBox.
Not sure why it's not working.
Please Help. Thanks


  1. CheckBox chkbox = new CheckBox();
  2.  
  3. DataGridBoolColumn discontinuedCol = new DataGridBoolColumn();
  4. discontinuedCol.MappingName = "chkbox ";
  5. discontinuedCol.HeaderText = "Select";
  6. discontinuedCol.Width = 30;
  7. discontinuedCol.AllowNull = false;
  8.  
  9. //add column to DGTStyle
  10. DGTStyle.GridColumnStyles.Add(discontinuedCol);
  11. DGTStyle.GridColumnStyles.Add(DGTcol2);
  12. DGTStyle.GridColumnStyles.Add(DGTcol3);
  13. DGTStyle.GridColumnStyles.Add(DGTcol4);
  14.  
  15. dataGrid1.TableStyles.Add(DGTStyle);
Last edited by LennieKuah; 25 Days Ago at 3:20 am. Reason: type error
Have a Good Day.

Cheers,
Lennie
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 117
Reputation: vinnijain is an unknown quantity at this point 
Solved Threads: 10
vinnijain vinnijain is offline Offline
Junior Poster
 
0
  #8
25 Days Ago
Read the following article :

http://www.vbdotnetheaven.com/Upload...gDatagrid.aspx

Hope it will help....
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
  #9
24 Days Ago
Hi Vinnijian,

I did have a look at the URL site with VB format script and compared it with my C# format script. Logically it looks very similiar. The VB script end result shows the DataGrid with CheckBox but not my version. I am very puzzled.

HELP.........PLEASE HELP.........
Have a Good Day.

Cheers,
Lennie
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 117
Reputation: vinnijain is an unknown quantity at this point 
Solved Threads: 10
vinnijain vinnijain is offline Offline
Junior Poster
 
0
  #10
24 Days Ago
From the property window of DataGridView Select the Columns Property.
Click on the (Collection) button .
From this window click on "Add" button.
select "Type" as "GridViewCheckboxColumn"
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