MultiColumn Combo - Format Text

3 posts, 0 answers
  1. AdrianG
    AdrianG avatar
    17 posts
    Member since:
    Jun 2013

    Posted 10 Feb 2015 Link to this post

    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. Ralitsa
    Admin
    Ralitsa avatar
    176 posts

    Posted 11 Feb 2015 Link to this post

    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.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. AdrianG
    AdrianG avatar
    17 posts
    Member since:
    Jun 2013

    Posted 11 Feb 2015 in reply to Ralitsa Link to this post

    Hi Ralitsa

    Just to confirm that works. Thanks very much.

    Regards

    Adrian
Back to Top