This is a migrated thread and some comments may be shown as answers.

Listbox with Checkboxes

3 Answers 175 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Paul Exler
Top achievements
Rank 1
Paul Exler asked on 28 Apr 2010, 04:51 PM
Hi everyone :)

I have the following situation:
In my GridView, I have a DataColumn with a CellEditTemplate.
In this CellEditTemplate, I need a DataTemplate with a RadDropDownButton, that has a ListBox (with checkboxes) as DropDownContent.

In code it looks like this:

<UserControl.Resources> 
        <DataTemplate x:Key="templateLanguagesItem"
            <Grid> 
                <CheckBox Name="chkLanguage" Content="{Binding LANGUAGENAME}" d:LayoutOverrides="Width, Height"/> 
            </Grid> 
        </DataTemplate>      
    </UserControl.Resources> 
 
 
<telerik:RadGridView AutoGenerateColumns="False" HorizontalAlignment="Stretch" Margin="0,30,0,0" Name="grdBenutzer" VerticalAlignment="Stretch" ItemsSource="{Binding ElementName=UserDomainDataSource, Path=Data}"
            <telerik:RadGridView.Columns>                 
                <telerik:GridViewDataColumn Header="Languages" DataMemberBinding="{Binding LANGUAGES, Mode=TwoWay}" Width="120"
                    <telerik:GridViewDataColumn.CellEditTemplate> 
                        <DataTemplate> 
                            <StackPanel> 
                                 
                                <telerik:RadDropDownButton Height="39" Content="Test" VerticalAlignment="Top"
                                    <telerik:RadDropDownButton.DropDownContent> 
                                        <ListBox Width="150" Height="200" ItemTemplate="{StaticResource templateLanguagesItem}" ItemsSource="{Binding Data, Source={StaticResource LanguageTestSource}}"/> 
                                    </telerik:RadDropDownButton.DropDownContent> 
                                </telerik:RadDropDownButton>                                 
                            </StackPanel> 
                        </DataTemplate> 
                    </telerik:GridViewDataColumn.CellEditTemplate> 
                </telerik:GridViewDataColumn> 
            </telerik:RadGridView.Columns> 
        </telerik:RadGridView> 

This works correct. I can open the dropDownButton and get a List of Languages in it with checkboxes.

Now I don't have an idea, how to get the selected checkboxes as one string back in the field "LANGUAGES".
I want to have a string which seperate's the selected items with a comma.

Example:

x Language 1
   Language 2
x Language 3

Now I want a string like "Language 1, Language 3". This should be written in the DataMember of the column.
Hope my explaination is clear.

How can I do this?

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 03 May 2010, 09:57 AM
Hi Paul Exler,

Since the scenario requires some custom logic to translate the selected values into a coma separated list, the best approach here would be :

Wrap the DropDownButton in a user control and handle this logic in the code-behind of the user control :

1. Create a new User control which has the RadDropDownButton with the Listbox inside.
2. Create a Property for that user control of type string called  SelectedItems
3. In the codebehind of the user control handle the SelecteionChanged event of the ListBox and update the value of the SelectedItems property of your user control whenever that event is raised.

After you have this user control , you just need to place it into the CellTemplate and bind the SelectedItems property two way ,

If this sounds complicated, just let me know and I will prepare a small sample for you . 

Sincerely yours,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Paul Exler
Top achievements
Rank 1
answered on 05 May 2010, 09:42 AM
Hi Pavel Pavlov,

thank you for your answer.
I get the idea, but I failed to implement this.
I searched for an answer for a while, but don't have an solution.
My main problem is: How to get all the selected checkboxes in the Selectionchanged-Event of the ListBox?
I only get the data items, not my ListBoxItem.

Could you please help me with a small sample. I would be very thankful!
0
Accepted
Pavel Pavlov
Telerik team
answered on 05 May 2010, 11:01 AM
Hello Paul Exler,

I have prepared a small implementation for you to use as a start point. Please find it attached

All the best,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
General Discussions
Asked by
Paul Exler
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Paul Exler
Top achievements
Rank 1
Share this question
or