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

comboBox, which contains list of checkBoxes

21 Answers 540 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Dandan
Top achievements
Rank 1
Dandan asked on 08 Mar 2009, 11:32 AM

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

21 Answers, 1 is accepted

Sort by
0
Dandan
Top achievements
Rank 1
answered on 11 Mar 2009, 09:05 AM
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
0
Hristo
Telerik team
answered on 12 Mar 2009, 11:50 AM
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.
0
Dandan
Top achievements
Rank 1
answered on 16 Mar 2009, 11:12 AM
Thanks!
0
Steve Johnson
Top achievements
Rank 1
answered on 22 Mar 2010, 08:25 AM
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
0
Steve Johnson
Top achievements
Rank 1
answered on 22 Mar 2010, 08:25 AM
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
0
Steve Johnson
Top achievements
Rank 1
answered on 22 Mar 2010, 08:26 AM
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
0
Steve Johnson
Top achievements
Rank 1
answered on 22 Mar 2010, 08:27 AM
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
0
Steve Johnson
Top achievements
Rank 1
answered on 22 Mar 2010, 08:28 AM
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
0
Wolfgang Kaiser
Top achievements
Rank 1
answered on 27 Apr 2010, 11:12 PM

On 2010 Q1 i get the error:

 

SelectionBoxItemTemplate

is read-only.  Is there still a way to change the text in the selection box?
0
Terry Webster
Top achievements
Rank 1
answered on 30 Apr 2010, 04:57 PM
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)    
0
Valeri Hristov
Telerik team
answered on 03 May 2010, 08:51 AM
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.
0
Terry Webster
Top achievements
Rank 1
answered on 10 May 2010, 04:12 PM
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
0
Kiran Ghanwat
Top achievements
Rank 1
answered on 12 May 2010, 02:28 PM

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

 

0
Valeri Hristov
Telerik team
answered on 12 May 2010, 02:33 PM
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.
0
Kiran Ghanwat
Top achievements
Rank 1
answered on 12 May 2010, 02:58 PM
Hi,
Valeri Hristov 

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

    Thanks,
Kiran Ghanwat.
0
Valeri Hristov
Telerik team
answered on 12 May 2010, 03:17 PM
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.
0
Hector
Top achievements
Rank 1
answered on 19 Aug 2010, 07:22 PM
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 ?
0
Konstantina
Telerik team
answered on 24 Aug 2010, 03:03 PM
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
0
Biruh MEKONNEN
Top achievements
Rank 1
answered on 22 Dec 2010, 01:58 PM
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.
0
manoj savalia
Top achievements
Rank 2
answered on 01 Feb 2012, 10:27 PM
But how to bind dynamic data in selectionTemplete??
0
swarup
Top achievements
Rank 2
answered on 24 Jan 2016, 02:37 AM

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 .

Tags
ComboBox
Asked by
Dandan
Top achievements
Rank 1
Answers by
Dandan
Top achievements
Rank 1
Hristo
Telerik team
Steve Johnson
Top achievements
Rank 1
Wolfgang Kaiser
Top achievements
Rank 1
Terry Webster
Top achievements
Rank 1
Valeri Hristov
Telerik team
Kiran Ghanwat
Top achievements
Rank 1
Hector
Top achievements
Rank 1
Konstantina
Telerik team
Biruh MEKONNEN
Top achievements
Rank 1
manoj savalia
Top achievements
Rank 2
swarup
Top achievements
Rank 2
Share this question
or