Skip to main content
Home Forums General Silverlight Getting Started how to create Grid with select all checkbox
8 replies. Latest Post by sladapter on May 27, 2009.
(0)
shiva.
Member
160 points
50 Posts
06-26-2008 3:31 AM |
Hi,
I want to have a data grid column with checkbox where header is also a checkbox so that when i check the header checkbox all the checkbox in that column should be selected. What i need is jus like that which we have in our mailing sites(select all).
Thanks in advance
SteveWong
Contributor
6343 points
1,281 Posts
06-26-2008 5:11 AM |
after the checked event in the checkbox at the 2nd column inside the DataGrid called MyData
{ var u = from element in Mydata.Columns[2] where element is CheckBox select element; foreach (itm in u) { ((CheckBox)itm).IsChecked = true; } }
sladapter
All-Star
17439 points
3,172 Posts
06-26-2008 11:54 AM |
Since you have the datasource that bind to the DataGrid, if you set your DataField that bind to the CheckBoxColumn to True for your DataList, all the check box will be checked automatically.
Just remember, Silverlight is data centric. You can always change the data to change the UI. You do not have to access the UI control to change the Data.
06-27-2008 4:02 AM |
Hello thanks for your answer, but what i need is different. i want to know how can i show a checkbox in the header of the column.
Thanks
06-27-2008 8:50 AM |
You can set any control or composite control to the Column.Header.
If you do it in code:
StackPanel sp = new StackPanel();
TextBlock t= new TextBlock();
t.Text = "YourHeaderText";
sp.Children.Add(t);
CheckBox c = new CheckBox();
sp.Children.Add(c);
theColumn.Header = sp;
Niranjan_KC
10 points
8 Posts
05-11-2009 10:44 AM |
Hi i am also having the same scenario. when i am trying to put a checkbox in the Header i am getting an error saying "The Element is already a child" kind. How can i desing the XAML..
05-12-2009 9:46 AM |
"The Element is already a child" means you are trying to add an element which is already in the visual tree. You can not add the same element more than once to the visual tree. Make sure your element has unique ID.
Also the code I provided (setting a control to the DataGrid.Header) no longer works since SL2 final release (it only worked in SL2 beta). You need to set a Header Template to define the header now.
05-22-2009 9:02 AM |
Hi Sladapter,
Thanks for ur reply. But can jus help me with the code as to how to do this.
05-27-2009 10:13 AM |
Niranjan_KC:Hi Sladapter, Thanks for ur reply. But can jus help me with the code as to how to do this.
Read this thread: http://silverlight.net/forums/p/30592/101414.aspx#101414