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

RadComboBox bound to property of nullable object

5 Answers 130 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Hans
Top achievements
Rank 1
Veteran
Hans asked on 19 Feb 2020, 01:55 PM

Hi,

I have following RadComboBox:

<telerik:RadComboBox x:Name="cmbSvtAreaManagers" Grid.Row="0" Grid.Column="2"
                ItemsSource="{Binding SvtAreaManagers}"
                TextSearch.TextPath="DisplayPerson"
                DisplayMemberPath="DisplayPerson"
                SelectedValue="{Binding CurrentCustomerFabrics.AreaManagerID, Mode=TwoWay}"
                SelectedValuePath="PersonID"
                ClearSelectionButtonContent="{bx:LocalizeBinding ClearSelectedItem, Global=true}"
                ClearSelectionButtonVisibility="Visible">

As you can see, the SelectedValue is bound to the CurrentCustomerFabrics object (my Model class) defined in my ViewModel.

private CustomerFabricsModel customerFabricsModel;
public CustomerFabricsModel CurrentCustomerFabrics
{
    get { return customerFabricsModel; }
    set
    {
        if (customerFabricsModel != value)
        {
            customerFabricsModel = value;
            NotifyPropertyChanged();
        }
    }
}

 

When the form is launched, the CurrentCustomerFabrics object is null (it's not initialized) so I would expect to see an empty combobox, but instead the first record is shown (SelectedIndex = 0).  How is this possible ?

Regards,
Hans

 

 

 

5 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 24 Feb 2020, 09:46 AM

Hi Hans,

Thank you for the provided code snippet.

I wasn't able to reproduce this behavior with the SelectedIndex. Looking at the first code snippet, the SelectedValue is bind to a sub-property (AreaManagerID) of the CurrentCustomerFabrics object. Can you try to leave only the CurrentCustomerFabrics property and remove the SelectedValuePath property? This way when you select an item CurrentCustomerFabrics will be set to this item. After that, you can get your AreaManagerID property. Can you give this approach a try and let me know if it works for you?

Regards,
Dinko
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Hans
Top achievements
Rank 1
Veteran
answered on 26 Feb 2020, 12:59 PM

Hi Dinko,

this will not work because the CurrentCustomerFabrics object is not of the same type as the ItemsSource (SvtAreaManagers).

Regards,
Hans

0
Dinko | Tech Support Engineer
Telerik team
answered on 02 Mar 2020, 08:09 AM

Hello Hans,

To avoid any misunderstanding is it possible to prepare a sample project which mimics your set-up and send it to me. This way I can have a better look at your implementation and think for a possible workaround.

I am looking forward to your reply.

Regards,
Dinko
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Hans
Top achievements
Rank 1
Veteran
answered on 06 Mar 2020, 10:31 AM

Hi Dinko,

I made a sample project but was unable to reproduce the problem.  I have spent a lot of time searching for the cause of the problem, without result.  For now, my solution is to initialize my CurrentCustomerFabrics object in the constructor of my ViewModel.

Regards,
Hans

 
0
Dinko | Tech Support Engineer
Telerik team
answered on 06 Mar 2020, 01:37 PM

Hi Hans,

I am happy to hear that you have found a solution for this behavior. If you manage to isolate this in a standalone project, you can send it to us so we can further investigate this.

Regards,
Dinko
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ComboBox
Asked by
Hans
Top achievements
Rank 1
Veteran
Answers by
Dinko | Tech Support Engineer
Telerik team
Hans
Top achievements
Rank 1
Veteran
Share this question
or