Display selected value in ComboBox with Checkbox

3 posts, 0 answers
  1. Prasanna
    Prasanna avatar
    2 posts
    Member since:
    Nov 2008

    Posted 21 Nov 2008 Link to this post

    I am creating a combobox in which I have placed check boxes which allows me multiple selection. I tried it in two ways:

    1. I used a collection of objects of entities defined by me.
    2. Created a datatable and then assigned it to the combobox.

    In both the approaches I have same problem of showing the seleced items with check box selected in the combobox.

    I have used follwoing code, which is showing me values correctly in the combobox but the problem occures when I want to show the selected item's check box selected. Can anyone suggest me a solution for this Or if you have any other better idea to implement the multiple selecte combobox then I will be greatful to you.
    i have used :

    <ComboBox  Name="cboBox1"
                                  Style="{StaticResource ComboBox}" ItemsSource="{Binding}"> 
                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                        <CheckBox Margin="3" Name="chkInsideCboBox1"
                                                  DataContext="{Binding ElementName=BusinessEntityName, Path=BusinessEntityId}"
                                                  IsChecked="{Binding Path=Default}"  Style="{StaticResource CheckBoxFilter}"></CheckBox>
                                        <TextBlock Text="{Binding Path=BusinessEntityNameField}" ></TextBlock>

    Thanks in advance
  2. Prasanna
    Prasanna avatar
    2 posts
    Member since:
    Nov 2008

    Posted 26 Nov 2008 Link to this post

    I got the solution.
    XAML Code:




    <ComboBox Name="cboBox1" Style="{StaticResource ComboBox}" ItemsSource="{Binding}" > 
    <ListBox x:Name="lstInsideComboBox" ItemsSource="{Binding}">  
    <CheckBox Name="chkInsideList" Click="chkInsideList_Checked" Content="{Binding Path=Content_To_Display}"   
     IsChecked="{Binding Path=ISSELECTED}"></CheckBox> 

    Now you have to assign the datacontext of your list inside the combo box.


    lstInsideComboBox.DataContext = dtSourceForList

    The datatable which you are assigning as DataContext to the list should have atleast two columns.
    1. Column Content_To_Display : this will be content which you want to display in combo box.
    2. Column ISSELECTED : this will be a column of bit value which will have either True or False. And on the basis of this value,
        check box will be checked.

    You may improve the look of this combobox by applying some style.




  3. Murray
    Murray avatar
    121 posts
    Member since:
    Aug 2010

    Posted 04 Oct 2010 Link to this post

    Hi Prasanna

    Could you post the full code including the Click event?
Back to Top