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

Html tags in selected value

4 Answers 159 Views
MultiColumn ComboBox
This is a migrated thread and some comments may be shown as answers.
OD
Top achievements
Rank 1
OD asked on 02 Sep 2011, 01:52 PM
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 :)

4 Answers, 1 is accepted

Sort by
0
OD
Top achievements
Rank 1
answered on 07 Sep 2011, 09:55 AM
up !
0
Peter
Telerik team
answered on 08 Sep 2011, 09:04 AM
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 >>

0
OD
Top achievements
Rank 1
answered on 08 Sep 2011, 10:23 AM
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 ?



0
Peter
Telerik team
answered on 08 Sep 2011, 03:39 PM
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 >>

Tags
MultiColumn ComboBox
Asked by
OD
Top achievements
Rank 1
Answers by
OD
Top achievements
Rank 1
Peter
Telerik team
Share this question
or