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
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
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(this, new 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.
Thanks,
Steve
Thanks,
Steve
Thanks,
Steve
Thanks,
Steve
Thanks,
Steve
On 2010 Q1 i get the error:
SelectionBoxItemTemplate
is read-only. Is there still a way to change the text in the selection box?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)
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.
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
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
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.
Valeri Hristov
Thanks for your reply.
I changed SelectionBoxItemTemplate to SelectionBoxItem. But, I am getting same error. :(
Thanks,
Kiran Ghanwat.
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.
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
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.
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 .