Skip to main content

Microsoft Silverlight

Answered Question how to create Grid with select all checkboxRSS Feed

(0)

shiva.
shiva.

Member

Member

160 points

50 Posts

how to create Grid with select all checkbox

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
SteveWong

Contributor

Contributor

6343 points

1,281 Posts

Re: how to create Grid with select all checkbox

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;
               }
           }

Regards,
SteveWong (HongKong)
Please mark post as answer if they help you

Client App Dev

sladapter
sladapter

All-Star

All-Star

17439 points

3,172 Posts

Re: how to create Grid with select all checkbox

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.

 

 

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

shiva.
shiva.

Member

Member

160 points

50 Posts

Re: Re: how to create Grid with select all checkbox

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

sladapter
sladapter

All-Star

All-Star

17439 points

3,172 Posts

Answered Question

Re: Re: how to create Grid with select all checkbox

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;

 

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

Niranjan_KC
Niranjan_KC

Member

Member

10 points

8 Posts

Re: Re: Re: how to create Grid with select all checkbox

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..

sladapter
sladapter

All-Star

All-Star

17439 points

3,172 Posts

Re: Re: Re: how to create Grid with select all checkbox

"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.

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

Niranjan_KC
Niranjan_KC

Member

Member

10 points

8 Posts

Re: Re: Re: Re: how to create Grid with select all checkbox

Hi Sladapter,

                           Thanks for ur reply. But can jus help me with the code as to how to do this.

sladapter
sladapter

All-Star

All-Star

17439 points

3,172 Posts

Re: Re: Re: Re: how to create Grid with select all checkbox

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

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities