Skip to content

Latest commit

 

History

History
66 lines (57 loc) · 2.2 KB

kb-combobox-datetimevalues-to-formattedstrings.md

File metadata and controls

66 lines (57 loc) · 2.2 KB
title description type page_title slug position tags ticketid res_type
Formatting Display of DateTime Values in RadComboBox
How to convert all DateTime values to list of formatted strings in RadComboBox.
how-to
How to Display DateTime Values as Formatted Strings in RadComboBox
kb-combobox-datetimevalues-to-formattedstrings
0
datetime, allowmultipleselection,multipleselectionboxtemplate
1622029
kb

Environment

Product Version 2023.2.718
Product RadComboBox for WPF

Description

How to format DateTime values to strings in the [Selection Box]({%slug radcombobox-general-information-visual-structure%}) element of the RadComboBox.

Solution

To get the desired effect, you can bind to the SelectedItems or to the original string value and use an IValueConverter to format the values.

[C#]

{{region kb-datetimevalues-to-formattedstrings}} public class DateTimeStringConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var dateStrings = ((string)value).Split(','); var format = parameter.ToString(); List result = new List(); foreach (string dateString in dateStrings) { var date = DateTime.Parse(dateString, CultureInfo.InvariantCulture); result.Add(date.ToString(format, CultureInfo.InvariantCulture)); } return string.Join(", ", result); } } {{endregion}}

In the XAML code you can use the RadComboBox MultipleSelectionBoxTemplate property and bind the Text property of the TextBlock to the context provided in the DataTemplate with the converter.

[XAML]

{{region kb-datetimevalues-to-formattedstrings}} <telerik:RadComboBox x:Name="radComboBox" AllowMultipleSelection="True"> telerik:RadComboBox.MultipleSelectionBoxTemplate </telerik:RadComboBox.MultipleSelectionBoxTemplate> </telerik:RadComboBox> {{endregion}}