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

MultiColumn Combo - Format Text

2 Answers 239 Views
MultiColumn ComboBox
This is a migrated thread and some comments may be shown as answers.
AdrianG
Top achievements
Rank 1
AdrianG asked on 10 Feb 2015, 02:23 PM
Hi

Could you advise how to set the format for the text display element of a MultiColumn combo box?

The data member part of the drop-down is associated with a DateTime column for which I have set the FormatString property to {0:dd.MM.yyyy HH:mm} via the designer.

So, the drop down shows dates in my required format (e.g. 10.02.2015 12:00) but the text still displays as 10/02/2015 12:00:00.

Any help with customizing the format would be greatly appreciated.

Thanks

Adrian

2 Answers, 1 is accepted

Sort by
0
Ralitsa
Telerik team
answered on 11 Feb 2015, 03:04 PM
Hi Adrian,

Thank you for contacting us. 

You can subscribe to the TextChanged event of the TextBoxItem to set the desired format of the date. Please refer to the following code snippet: 

 - subscribe to the event: 
this.radMultiColumnComboBox1.TextChanged += radMultiColumnComboBox1_TextChanged;

- format the text in the event handler:
bool isFormatting;
 
void radMultiColumnComboBox1_TextChanged(object sender, EventArgs e)
{
    if (isFormatting)
    {
        return;
    }
 
    isFormatting = true;
 
    if (this.radMultiColumnComboBox1.SelectedIndex != -1)
    {
        object value = this.radMultiColumnComboBox1.EditorControl.Rows[this.radMultiColumnComboBox1.SelectedIndex].Cells["Time"].Value;
 
        if (value != null)
        {
            DateTime time = (DateTime)value;
            string text = time.ToString("dd.MM.yyyy HH:mm");              
            this.radMultiColumnComboBox1.MultiColumnComboBoxElement.TextBoxElement.TextBoxItem.Text = text;
        }
    }
 
    isFormatting = false;
}

In attachments you can find a sample demo.  

Hope this will help you. Let me know if you have any another questions.

Regards,
Ralitsa
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
AdrianG
Top achievements
Rank 1
answered on 11 Feb 2015, 04:16 PM
Hi Ralitsa

Just to confirm that works. Thanks very much.

Regards

Adrian
Tags
MultiColumn ComboBox
Asked by
AdrianG
Top achievements
Rank 1
Answers by
Ralitsa
Telerik team
AdrianG
Top achievements
Rank 1
Share this question
or