RadMultiColumnComboBox: How can I prevent the ComboBox Editor from line breaking/word wrapping?

2 Answers 165 Views
MultiColumnComboBox
ClausDC
Top achievements
Rank 1
Iron
ClausDC asked on 17 May 2022, 09:04 AM | edited on 17 May 2022, 09:05 AM

Please consider the attached image.

How can I prevent the editor from line breaking when the selected item in the combobox fills out the whole (or more) width of the combobox editor? I want it to keep the height of a single line and just scroll the text, like in a single line textbox.

2 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 19 May 2022, 03:04 PM

Hello Claus,

To achieve your requirement, you can replace the default items panel of the control. You can do this using the following approach:

private void RadMultiColumnComboBox_Loaded(object sender, RoutedEventArgs e)
{
	var mccb = (RadMultiColumnComboBox)sender;
	var itemsControl = mccb.FindChildByType<SearchAutoCompleteBoxesItemsControl>();
	itemsControl.ItemsPanel = this.Resources["stackPanelTemplate"] as ItemsPanelTemplate;
}

<Window.Resources>
        <ItemsPanelTemplate x:Key="stackPanelTemplate">
            <StackPanel />
        </ItemsPanelTemplate>
</Window.Resources>

I hope that helps.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

ClausDC
Top achievements
Rank 1
Iron
commented on 20 May 2022, 07:40 AM | edited

Unfortunately, that doesn't work, the editor still gets wrapped. Probably because ultimately, the input box of the control is not a TextBox but an ItemsControl within a ScrollViewer. Even when forcing it in a single line, you still would need horizontal scrollbars which wouldn't fit at all.

It's just too different from a regular ComboBox.

We used regular RadComboBoxes before, which fit neatly into a "line". We wanted to see if we could relpace some with this control but the wrapping somewhat destroys the layout we had so far.

Martin Ivanov
Telerik team
commented on 25 May 2022, 07:22 AM

You are right. It seems that the custom items control implementation is forcing the height to increase. One way to avoid this is to modify the ControlTemplate of SearchAutoCompleteBox element (part of the MultiColumnComboBox' template).This will allow you to remove the ScrollViewer and set a fixed height to the control. You can find this approach shown in the attached project. I hope it helps. Note that the customized template is based on the default Office_Black theme. To use it for another theme, you should extract the associated template and apply the needed changes. 
0
ClausDC
Top achievements
Rank 1
Iron
answered on 07 Jun 2022, 03:02 PM

Actually I kind of found a solution: When setting the "SelectionBoxesVisibility" property to "Collapsed", the behavior of the control is pretty close to the desired behavior.

Unfortunately, the editor textbox (a RadWatermarkTextBox as I understand it after looking at the control templates) doesn't update to the selected item (through DisplayMemberPath), when the SelectedItem is changed through the data binding source. When changing it through the UI by typing or selection in the DropDown, it changes the displayed text correctly however.

It seems I can force it by subscribing to SelectionChanged/Loaded events and retrieving the RadWatermarkTextBox through FindChildByType and then setting the Text manually but this is kind of messy and not very elegant.

It would be nice if the RadWatermarkTextBox reacted to the changes in the data binding source.


Martin Ivanov
Telerik team
commented on 10 Jun 2022, 08:37 AM

I've tested this and the textbox is updated correctly when you update the SelectedItem. Can you check the attached project and tell me if I am missing anything?
ClausDC
Top achievements
Rank 1
Iron
commented on 10 Jun 2022, 08:47 AM

Yeah, I have to correct my initial assumption. It does update, however only when the contol is loaded in the VisualTree.

I was setting SelectedItem via binding before the control was loaded.  It appears that the text of the RadWatermarkTextBox doesn't initially get set. I solved this for now with the method described in my answer above by subscribing only to the Loaded event and setting the text of the RadWatermarkTextBox manually.

After that, it's not necessary to subscribe to SelectionChanged and updating the TextBox manually, like you wrote Martin.

Still, what remains is that the RadWatermarkTextBox should set its Text property to the initial value of SelectedItem, once it is loaded, I think.

Martin Ivanov
Telerik team
commented on 10 Jun 2022, 10:20 AM

Thank you for the additional description. It turns out that this is an issue in the control. Basically, the text is updated manually on SelectedItem changed, however, if you set the selection item before the control was loaded, the textbox part is not yet loaded, so its text cannot be assigned. I have logged a new bug report in the Telerik feedback portal where you can track its status. You can also find your Telerik points updated.

To work this around, you can use your approach, or one of the following options. You can use the Loaded event in order to reset the SelectedItem setting of the control.

private void RadMultiColumnComboBox_Loaded(object sender, RoutedEventArgs e)
{
	var mccb = (RadMultiColumnComboBox)sender;            
	var selection = mccb.SelectedItem;
	mccb.SetCurrentValue(RadMultiColumnComboBox.SelectedItemProperty, null);
	mccb.SetCurrentValue(RadMultiColumnComboBox.SelectedItemProperty, selection);
}

Or you can ensure that the SelectedItem property of your view model is set after the InitializeComponent call of the view that hosts the RadMultiColumnComboBox control.

Tags
MultiColumnComboBox
Asked by
ClausDC
Top achievements
Rank 1
Iron
Answers by
Martin Ivanov
Telerik team
ClausDC
Top achievements
Rank 1
Iron
Share this question
or