Html tags in selected value

5 posts, 0 answers
  1. QuizzBox
    QuizzBox avatar
    46 posts
    Member since:
    Jan 2011

    Posted 02 Sep 2011 Link to this post

    hey,
    i'm using the multicolum combobox with html tags in values.
    The list is beautiful but my problem is that when i select a bold string in my list for example, i see "<html><b>My value</b>" in the selectedvalue.
    An idea ? thanks :)
  2. QuizzBox
    QuizzBox avatar
    46 posts
    Member since:
    Jan 2011

    Posted 07 Sep 2011 Link to this post

    up !
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 08 Sep 2011 Link to this post

    Hello Nermond,

    The SelectedValue property contains the value represented by the DisplayMember property. That is why its value contains HTML tags. You can strip all HTML tags by using the following code:

    string strResult = Regex.Replace(strInput,@"<(.|\n)*?>",string.Empty);

    The HTML-like formatting is a feature integrated in our Telerik Presentation Framework. However, RadMultiColumnComboBox uses the default WinForms TextBox to allow editing. It cannot present rich text and HTML tags should be striped. You can do this by handling the TextChanged event. Please consider the code snippet below:

    radMultiColumnComboBox1.MultiColumnComboBoxElement.TextBoxElement.TextBoxItem.HostedControl.TextChanged += new EventHandler(HostedControl_TextChanged);
     
    void HostedControl_TextChanged(object sender, EventArgs e)
    {
        TextBox textbox = (TextBox)sender;
        textbox.Text = Regex.Replace(textbox.Text, @"<(.|\n)*?>",string.Empty);;
    }

    I hope this helps. If you need further assistance, please do not hesitate to ask.

    All the best,
    Peter
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  5. QuizzBox
    QuizzBox avatar
    46 posts
    Member since:
    Jan 2011

    Posted 08 Sep 2011 Link to this post

    Cool that works :)
    Thanks
    I've tried many times with the SelectedIndexChanged event, but was not the good event ^^

    Nother question: now i don't see the html tags, that's good, but the selected item is not html formated. Is there a way to enable html rendering without seeing the tags ?



  6. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 08 Sep 2011 Link to this post

    Hi Nermond,

    You cannot show an HTML formatted text in the TextBox. However, there is a work around which covers the case when you do not need to edit the text. You can hide the RadTextBox which is inside RadMultiColumnComboBox and put there a LightVisualElement that supports HTML-like formatting. Please consider the code snippet below:

    LightVisualElement lve = new LightVisualElement();
     
    private void Form_Load(object sender, EventArgs e)
    {                                                  radMultiColumnComboBox1.MultiColumnComboBoxElement.TextBoxElement.TextBoxItem.HostedControl.TextChanged += new EventHandler(HostedControl_TextChanged);
     
         lve.TextAlignment = ContentAlignment.MiddleLeft;
         lve.Alignment = ContentAlignment.MiddleLeft;
         lve.MaxSize = new Size(radMultiColumnComboBox1.Size.Width - 15, radMultiColumnComboBox1.Size.Height);
         radMultiColumnComboBox1.MultiColumnComboBoxElement.TextBoxElement.Visibility = ElementVisibility.Hidden;
         radMultiColumnComboBox1.MultiColumnComboBoxElement.Children.Add(lve);
    }
     
    private void HostedControl_TextChanged(object sender, EventArgs e)
    {
    TextBox textbox = (TextBox)sender;
    lve.Text = textbox.Text;
    }

    Do not hesitate to contact us if you have other questions.

    Regards,
    Peter
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top
UI for WinForms is Visual Studio 2017 Ready