comboBox, which contains list of checkBoxes

22 posts, 0 answers
  1. Dandan
    Dandan avatar
    17 posts
    Member since:
    Mar 2009

    Posted 08 Mar 2009 Link to this post

    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

  2. Dandan
    Dandan avatar
    17 posts
    Member since:
    Mar 2009

    Posted 11 Mar 2009 Link to this post

    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
  3. DevCraft banner
  4. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 12 Mar 2009 Link to this post

    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.
  5. Dandan
    Dandan avatar
    17 posts
    Member since:
    Mar 2009

    Posted 16 Mar 2009 Link to this post

    Thanks!
  6. Steve Johnson
    Steve Johnson avatar
    24 posts
    Member since:
    Feb 2010

    Posted 22 Mar 2010 Link to this post

    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
  7. Steve Johnson
    Steve Johnson avatar
    24 posts
    Member since:
    Feb 2010

    Posted 22 Mar 2010 Link to this post

    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
  8. Steve Johnson
    Steve Johnson avatar
    24 posts
    Member since:
    Feb 2010

    Posted 22 Mar 2010 Link to this post

    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
  9. Steve Johnson
    Steve Johnson avatar
    24 posts
    Member since:
    Feb 2010

    Posted 22 Mar 2010 Link to this post

    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
  10. Steve Johnson
    Steve Johnson avatar
    24 posts
    Member since:
    Feb 2010

    Posted 22 Mar 2010 Link to this post

    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
  11. Wolfgang Kaiser
    Wolfgang Kaiser avatar
    9 posts
    Member since:
    Dec 2009

    Posted 27 Apr 2010 Link to this post

    On 2010 Q1 i get the error:

     

    SelectionBoxItemTemplate

    is read-only.  Is there still a way to change the text in the selection box?
  12. Terry Webster
    Terry  Webster avatar
    21 posts
    Member since:
    Dec 2009

    Posted 30 Apr 2010 Link to this post

    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)    
  13. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 03 May 2010 Link to this post

    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.
  14. Terry Webster
    Terry  Webster avatar
    21 posts
    Member since:
    Dec 2009

    Posted 10 May 2010 Link to this post

    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
  15. Kiran Ghanwat
    Kiran Ghanwat avatar
    38 posts
    Member since:
    Nov 2009

    Posted 12 May 2010 Link to this post

    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

     

  16. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 12 May 2010 Link to this post

    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.
  17. Kiran Ghanwat
    Kiran Ghanwat avatar
    38 posts
    Member since:
    Nov 2009

    Posted 12 May 2010 Link to this post

    Hi,
    Valeri Hristov 

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

        Thanks,
    Kiran Ghanwat.
  18. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 12 May 2010 Link to this post

    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.
  19. Hector
    Hector avatar
    13 posts
    Member since:
    Apr 2009

    Posted 19 Aug 2010 Link to this post

    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 ?
  20. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 24 Aug 2010 Link to this post

    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
  21. Biruh MEKONNEN
    Biruh MEKONNEN avatar
    23 posts
    Member since:
    Apr 2010

    Posted 22 Dec 2010 Link to this post

    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.
  22. manoj savalia
    manoj savalia avatar
    11 posts
    Member since:
    Jul 2009

    Posted 01 Feb 2012 Link to this post

    But how to bind dynamic data in selectionTemplete??
  23. swarup
    swarup avatar
    2 posts
    Member since:
    Jan 2016

    Posted 23 Jan Link to this post

    Hello EveryOne,

     My combobox contains list of check boxes.

    but can i know is it possible to check checkboxes that are present in combo box dynamically in server side.

    Means when i fire a event it will check the selected check box i want to check .

Back to Top
DevCraft banner