Cascading Combo Box predicament

1 posts, 0 answers
  1. Ubuntu
    Ubuntu avatar
    89 posts
    Member since:
    Jul 2012

    Posted 09 Apr 2013 Link to this post

    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"
        SelectedValue="{Binding Path=CurrentTaxpayer.MgovID, Mode=TwoWay,NotifyOnValidationError=True,ValidatesOnExceptions=True}"
        SelectedItem="{Binding Source={StaticResource ContextProxy},Path=DataSource.SelectedGov,Mode=TwoWay}">
        <i:EventTrigger EventName="SelectionChanged">
        <i:InvokeCommandAction Command="{Binding SelectionChangedGovCommand}"
                                           CommandParameter="{Binding SelectedItem, ElementName=cbxMGov}" />

    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

Back to Top