Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > ComboBox > comboBox, which contains list of checkBoxes

Not answered comboBox, which contains list of checkBoxes

Feed from this thread
  • Dandan avatar

    Posted on Mar 8, 2009 (permalink)

    Hi,

    I have a comboBox, which contains list of checkBoxes (so, the user can choose more than one value in the checkBox).
    My question is if it possible that when the user wil close the comboBox, then he will see list of the checked values?

    Thanks,
    Dana

    Reply

  • Dandan avatar

    Posted on Mar 11, 2009 (permalink)

    Hi

    I'll try to explain it in a different way.

    I'm using RadComboBox.
    The items inside it are CheckBoxes.
    The user is able check some value and then to close the combo box by clicking on its button.
    I want to let the user to see his selections in the combo box title (means, in the selected item cell of the combo box).

    For example:

    I can have the following values in my combo box:

    1
    2
    3
    4
    5
    6

    If the user selects 1, 3, and 6 and closes the combo box he shall see "1,3,6" in the combo box selected item cell.

    Can I do that?

    Thanks

    Dana

    Reply

  • Hristo Hristo admin's avatar

    Posted on Mar 12, 2009 (permalink)

    Hi Dandan,

    I'm sorry for the late response.
    Here is an example demonstrating how to show the text of the checked items. This is not the only way and can be improved further.

    This is the page XAML:
    <UserControl x:Class="SilverlightDockingDemo.Page48" 
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
            xmlns:local="clr-namespace:SilverlightDockingDemo;assembly=SilverlightDockingDemo" 
            xmlns:input="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" 
            Width="400" Height="300">  
        <UserControl.Resources> 
            <local:ComboBoxSource x:Key="comboSource">  
                <local:MyDataItem Text="1" /> 
                <local:MyDataItem Text="2" /> 
                <local:MyDataItem Text="3" /> 
                <local:MyDataItem Text="4" IsSelected="True" /> 
                <local:MyDataItem Text="5" IsSelected="True" /> 
                <local:MyDataItem Text="6" /> 
            </local:ComboBoxSource> 
        </UserControl.Resources> 
        <Grid x:Name="LayoutRoot" Background="White">  
            <input:RadComboBox VerticalAlignment="Center" ItemsSource="{Binding}" 
                    DataContext="{StaticResource comboSource}">  
                <input:RadComboBox.ItemTemplate> 
                    <DataTemplate> 
                        <CheckBox IsThreeState="False" IsChecked="{Binding IsSelected, Mode=TwoWay}" 
                                Content="{Binding Text}" /> 
                    </DataTemplate> 
                </input:RadComboBox.ItemTemplate> 
                <input:RadComboBox.SelectionBoxItemTemplate> 
                    <DataTemplate> 
                        <TextBlock DataContext="{StaticResource comboSource}" Text="{Binding SelectedItemsText}" /> 
                    </DataTemplate> 
                </input:RadComboBox.SelectionBoxItemTemplate> 
            </input:RadComboBox> 
        </Grid> 
    </UserControl> 

    and this is the page code-behind:
    using System;  
    using System.Collections.ObjectModel;  
    using System.ComponentModel;  
    using System.Text;  
    using System.Windows.Controls;  
     
    namespace SilverlightDockingDemo  
    {  
        public partial class Page48 : UserControl  
        {  
            public Page48()  
            {  
                InitializeComponent();  
            }  
        }  
     
        public class MyDataItem : INotifyPropertyChanged  
        {
            #region INotifyPropertyChanged Members  
     
            /// <summary>  
            ///     Called when the value of a property changes.  
            /// </summary>  
            /// <param name="propertyName">The name of the property that has changed.</param>  
            protected virtual void OnPropertyChanged(String propertyName)  
            {  
                if (String.IsNullOrEmpty(propertyName))  
                {  
                    return;  
                }  
                if (PropertyChanged != null)  
                {  
                    PropertyChanged(thisnew PropertyChangedEventArgs(propertyName));  
                }  
            }  
     
            /// <summary>  
            ///     Raised when the value of one of the properties changes.  
            /// </summary>  
            public event PropertyChangedEventHandler PropertyChanged;
            #endregion  
     
            #region Text  
     
            private string text;  
            /// <summary>  
            /// Gets or sets Text.  
            /// </summary>  
            public string Text  
            {  
                get 
                {  
                    return this.text;  
                }  
                set 
                {  
                    if (this.text != value)  
                    {  
                        this.text = value;  
                        OnPropertyChanged("Text");  
                    }  
                }  
            }
            #endregion  
     
            #region IsSelected  
     
            private bool selected;  
            /// <summary>  
            /// Gets or sets IsSelected.  
            /// </summary>  
            public bool IsSelected  
            {  
                get 
                {  
                    return this.selected;  
                }  
                set 
                {  
                    if (this.selected != value)  
                    {  
                        this.selected = value;  
                        OnPropertyChanged("IsSelected");  
                    }  
                }  
            }
            #endregion  
        }  
     
        public class ComboBoxSource : ObservableCollection<MyDataItem>  
        {
            #region SelectedItemsText  
     
            private string text;  
            /// <summary>  
            /// Gets or sets SelectedItemsText.  
            /// </summary>  
            public string SelectedItemsText  
            {  
                get 
                {  
                    return this.text;  
                }  
                set 
                {  
                    if (this.text != value)  
                    {  
                        this.text = value;  
                        this.OnPropertyChanged(new PropertyChangedEventArgs("SelectedItemsText"));  
                    }  
                }  
            }
            #endregion  
     
            protected override void OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)  
            {  
                if (e.NewItems != null)  
                {  
                    foreach (MyDataItem item in e.NewItems)  
                    {  
                        item.PropertyChanged += new PropertyChangedEventHandler(OnItemPropertyChanged);  
                    }  
                }  
                if (e.OldItems != null)  
                {  
                    foreach (MyDataItem item in e.OldItems)  
                    {  
                        item.PropertyChanged -= new PropertyChangedEventHandler(OnItemPropertyChanged);  
                    }  
                }  
                base.OnCollectionChanged(e);  
                this.UpdateSelectedText();  
            }  
     
            public void UpdateSelectedText()  
            {  
                int itemsCount = this.Items.Count;  
                StringBuilder sb = new StringBuilder();  
                for (int i = 0; i < itemsCount; i++)  
                {  
                    MyDataItem item = this.Items[i];  
                    if (item.IsSelected)  
                    {  
                        sb.AppendFormat("{0}, ", item.Text);  
                    }  
                }  
     
                if (sb.Length > 2)  
                {  
                    sb.Remove(sb.Length - 2, 2);  
                }  
     
                this.SelectedItemsText = sb.ToString();  
            }  
     
            private void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e)  
            {  
                if (e.PropertyName == "IsSelected")  
                {  
                    this.UpdateSelectedText();  
                }  
            }  
        }  

    Let me know if you need more information.

    Greetings,
    Hristo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Dandan avatar

    Posted on Mar 16, 2009 (permalink)

    Thanks!

    Reply

  • Posted on Mar 22, 2010 (permalink)

    Now that SelectionBoxItemTemplate is read-only do you have an alternate solution to display the string of csv's?  I can't figure out how to make it show up.
    Thanks,
    Steve

    Reply

  • Posted on Mar 22, 2010 (permalink)

    Now that SelectionBoxItemTemplate is read-only do you have an alternate solution to display the string of csv's?  I can't figure out how to make it show up.
    Thanks,
    Steve

    Reply

  • Posted on Mar 22, 2010 (permalink)

    Now that SelectionBoxItemTemplate is read-only do you have an alternate solution to display the string of csv's?  I can't figure out how to make it show up.
    Thanks,
    Steve

    Reply

  • Posted on Mar 22, 2010 (permalink)

    Now that SelectionBoxItemTemplate is read-only do you have an alternate solution to display the string of csv's?  I can't figure out how to make it show up.
    Thanks,
    Steve

    Reply

  • Posted on Mar 22, 2010 (permalink)

    Now that SelectionBoxItemTemplate is read-only do you have an alternate solution to display the string of csv's?  I can't figure out how to make it show up.
    Thanks,
    Steve

    Reply

  • Wolfgang Kaiser avatar

    Posted on Apr 27, 2010 (permalink)

    On 2010 Q1 i get the error:

     

    SelectionBoxItemTemplate

    is read-only.  Is there still a way to change the text in the selection box?

    Reply

  • Terry Webster avatar

    Posted on Apr 30, 2010 (permalink)

    I am getting the following error using your example.  Any Ideas on how to correct?

    Microsoft JScript runtime error: Unhandled Error in Silverlight Application
    Code: 4004   
    Category: ManagedRuntimeError      
    Message: System.Windows.Markup.XamlParseException:  [Line: 0 Position: 0] ---> System.Windows.Markup.XamlParseException: The property 'System.Windows.Controls.Panel.Children' is set more than once. [Line: 725 Position: 36]
       at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
       at MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)
       at MS.Internal.XcpImports.FrameworkElement_ApplyTemplate(FrameworkElement frameworkElement)
       at System.Windows.Controls.ItemContainerGenerator.LayoutStatesManager.GetElementRoot(Boolean templatesAreGenerated)
       at System.Windows.Controls.ItemContainerGenerator.LayoutStatesManager.Load()
       at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject container)
       at System.Windows.Controls.ItemsControl.AddVisualChild(Int32 containerIndex, DependencyObject container, Boolean needPrepareContainer)
       at System.Windows.Controls.ItemsControl.AddContainers()
       at System.Windows.Controls.ItemsControl.RecreateVisualChildren(IntPtr unmanagedObj)
       --- End of inner exception stack trace ---
       at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
       at MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)
       at MS.Internal.XcpImports.FrameworkElement_ApplyTemplate(FrameworkElement frameworkElement)
       at System.Windows.Controls.ScrollContentPresenter.HookupScrollingComponents()
       at System.Windows.Controls.ScrollContentPresenter.OnApplyTemplate()
       at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)    

    Reply

  • Valeri Hristov Valeri Hristov admin's avatar

    Posted on May 3, 2010 (permalink)

    Hello Terry,

    You are using Silverlight 3 assemblies in a Silverlight 4 application, hence the exception. You can find more information about the problem here:
    http://www.telerik.com/community/forums/silverlight/combobox/system-windows-controls-panel-children-is-set-more-than-once-line-339-position-18.aspx

    All the best,
    Valeri Hristov
    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.

    Reply

  • Terry Webster avatar

    Posted on May 10, 2010 (permalink)

    Great!  That fixed it. 

    However, I am trying to modify this example to work against a wcf service.  How would you go about handling the fact it doesn't go against a static resource?

    Thanks,

    Terry

    Reply

  • Kiran Ghanwat avatar

    Posted on May 12, 2010 (permalink)

    Hello Terry,

     At my side I m using SL Runtime- 4.0.50401.0 bt, I have SL SDK 3 and using telerik 2010.1.422.1030 assemblies.
    Even, Though I am getting same Error "SelectionBoxItemTemplate is read-only".

    Please reply.
    Thanks in advance,
    Kiran Ghanwat

     

    Reply

  • Valeri Hristov Valeri Hristov admin's avatar

    Posted on May 12, 2010 (permalink)

    Hi Kiran,

    Please, use the SelectionBoxItem property instead of SelectionBoxItemTemplate.

    Regards,
    Valeri Hristov
    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.

    Reply

  • Kiran Ghanwat avatar

    Posted on May 12, 2010 (permalink)

    Hi,
    Valeri Hristov 

        Thanks for your reply.
        I changed SelectionBoxItemTemplate to SelectionBoxItem. But, I am getting same error. :(

        Thanks,
    Kiran Ghanwat.

    Reply

  • Valeri Hristov Valeri Hristov admin's avatar

    Posted on May 12, 2010 (permalink)

    I apologize for the mistake, I wanted to suggest using the SelectionBoxTemplate property.

    Regards,
    Valeri Hristov
    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.

    Reply

  • Hector avatar

    Posted on Aug 19, 2010 (permalink)

    This is exactly what I needed, but the SubjecBoxTemplate does not show the selected items. I am using a models/view with my silverlight app. Do I have to change the SubjectBoxTemplate ?

    Reply

  • Konstantina Konstantina admin's avatar

    Posted on Aug 24, 2010 (permalink)

    Hello Hector,

    I am afraid I couldn't get you right. Could you please explain what exactly is the problem you are facing?

    Looking forward to your reply.

    All the best,
    Konstantina
    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

    Reply

  • Posted on Dec 22, 2010 (permalink)

    Hi,

    there are some solution about a combobox witl list of checkboxes in this thread:
    http://www.telerik.com/community/code-library/silverlight/general/a-multiselect-combobox.aspx

    I've posted mine with a select all feature. I hope it's going to work for you.

    regards, Biruh.

    Reply

  • manoj savalia avatar

    Posted on Feb 1, 2012 (permalink)

    But how to bind dynamic data in selectionTemplete??

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > ComboBox > comboBox, which contains list of checkBoxes
Related resources for "comboBox, which contains list of checkBoxes"

Silverlight ComboBox Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]