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

Mutliselect Text return null reference exception

1 Answer 109 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
shang
Top achievements
Rank 1
shang asked on 14 Mar 2018, 10:25 PM

I am enabling mulitpleselection of combobox and using Text field to bind a string value. After I use the multipleSelectionSeparator = "|", there is the null reference exception thrown. The binding field "BindText" has been initialized to empty string. There is no issue if I do not use multipleSelectionSeparator., so I am really confused why null reference is thrown and stack trace image is attached.

<telerik:RadComboBox x:Name="RadComboBox"                             

 IsReadOnly="False"                             

 IsEditable="False"                              

Text="{Binding BindText, Mode=OneWayToSource}"                             

 AllowMultipleSelection="True"                        

ItemsSource="{Binding BindTexts}"                             

 IsEnabled="{Binding IsEnabled}"                                

MultipleSelectionSeparator=";"         

/>

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 19 Mar 2018, 08:29 AM
Hello Shang Sun,

The error appears because the control expects that the Text property won't contain null value in the multiselection scenario. However, it seems that initially the binding returns a null value which messes up with the initial selection logic. To avoid the error you can set the FallbackValue property of the binding to an empty string. Here is an example in code:
<telerik:RadComboBox Text="{Binding Text, Mode=OneWayToSource, FallbackValue={x:Static system:String.Empty}}"/>
Where "system" points to "xmlns:system="clr-namespace:System;assembly=mscorlib"".

I hope that helps.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
ComboBox
Asked by
shang
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or