Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
XamDataGrid Binding ComboBoxItemsProvider to another Field
posted

Hello,

 I would like to create a datagrid that provides a list of States as a XamComboEditor and another that provides a list of Cities within a State as a XamComboEditor.  I am not sure how to accomplish this.  Basically I would like the selected item of the States to filter the ItemsSource of my Cities combobox.  Any thoughts?

Parents
No Data
Reply
  • 415
    posted

    Hi,

    There are probably a couple of different ways to implement this functionality in your application.

    Solution:

    1. Handle the EditModeStarting event of the xamDataGrid control.

    2. Check to see if the cell entering edit mode belongs to the City Field.

    3. If so, apply a filter to the collection that contains city information.

    I am attaching a sample as a proof-of-concept. Since you did not state the version of NetAdvantage for WPF you are using in your application, I used the latest and greatest 8.2. If you do not have 8.2, you will have to replace the references in the project

    There are other ways to implement this functionality based on your data source. If your State object expose a nested collection of City objects, you can use a RelativeSource binding to retrieve the Cities in a particular State. For example, the Field that contains the City information would use the following EditorStyle:

    <Style TargetType="{x:Type igEditors:XamComboEditor}">
        <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type igDP:DataRecordPresenter}}, Path=DataRecord.DataItem.State.Cities}" />
        <Setter Property="DisplayMemberPath" Value="CityName" />
    </Style>

    StatesAndCities.zip
Children