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

Cascading Combo Box predicament

0 Answers 54 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ubuntu
Top achievements
Rank 1
Ubuntu asked on 09 Apr 2013, 04:24 PM

Dear All,

I have a serious problem with Combo-Boxes, who doesn’t …!!
I am using two Rad-Combos to display related data, one is displaying the Governments the second 
accordingly displays the Regions, very basic scenario.

Everything is working fine when I have a New record, but when I try to Modify an existing record, here 
where it comes the issue.

                 
I am populating Rad-Combos using QueryableDomainServiceCollectionView as follows:
private QueryableDomainServiceCollectionView<Government> _gov;
public QueryableDomainServiceCollectionView<Government> Govs
{
    get { return _gov; }
    set { _gov = value; RaisePropertyChanged(() => Govs); }
}
                

Q: Can you please advise, If this is a good practices or not ?

Then I have a SelectedGov to hold the selecteditem from Rad-Combo back in VM:

private Government _selectedGov;
public Government SelectedGov
{
    get { return _selectedGov; }
    set { _selectedGov = value; RaisePropertyChanged(() => SelectedGov); }
}


And I am binding the Combo in XAML as follows:

<Telerik:RadComboBox x:Name="cbxMGov" IsEditable="True" IsReadOnly="True" Margin="0,0,0,5" Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="4"
    ItemsSource="{Binding Source={StaticResource ContextProxy},Path=DataSource.Govs,NotifyOnValidationError=True,ValidatesOnExceptions=True}"  MaxDropDownHeight="120" OpenDropDownOnFocus="True"
    SelectedValuePath="ID"
    SelectedValue="{Binding Path=CurrentTaxpayer.MgovID, Mode=TwoWay,NotifyOnValidationError=True,ValidatesOnExceptions=True}"
    DisplayMemberPath="Name"
    SelectedItem="{Binding Source={StaticResource ContextProxy},Path=DataSource.SelectedGov,Mode=TwoWay}">
 
    <i:Interaction.Triggers>
    <i:EventTrigger EventName="SelectionChanged">
    <i:InvokeCommandAction Command="{Binding SelectionChangedGovCommand}"
                                       CommandParameter="{Binding SelectedItem, ElementName=cbxMGov}" />
    </i:EventTrigger>
    </i:Interaction.Triggers>
</Telerik:RadComboBox>

When I modify a record I populate the Combo at the VM as follows:
if (Govs!=null) { if (Govs.HasChanges) Govs.RejectChanges(); }
Govs = DataService.GetGovernments();
Govs.AutoLoad = true;
I use rejectchanges for the QDSCV because it somtimes haschanges=true and cause troubles, I don't have a clue why this happens!

and here is how I trap the selectionchanged of the combo to populate the second combo (Regions):
private void SelectionChangedGov()
{
    if (SelectedGov == null) return;
    if (Regions != null)
             if (Regions.HasChanges) Regions.RejectChanges();
 
    Regions = DataService.GetRegionsByGovId(SelectedGov.ID);
    Regions.AutoLoad = true;
    Regions.LoadedData += (s, e) =>
    {
               // Indirect Assign the Selectedvalue
              CurrentItem.MgovID = SelectedGov.ID;
    };
}

as you see I am assigning the CurrentItem.GovID with the selected value from the combo this way, because the combo doesn't return the value into its properity SelectedValue, that is why I am using the SelectedItem to overcome this problem

The issue is; when I try to change the Gov combo, the region doesn't populate first time, them If I change it again and select different Gov the regions are populated as excpected ... this happens occasionally !!


I hope I explain the issue well

Best

No answers yet. Maybe you can help?

Tags
ComboBox
Asked by
Ubuntu
Top achievements
Rank 1
Share this question
or