0
votes

I'm using WPF, MVVM, DevExpress. I'm trying to create Grid Control With 4 Columns. Cloumns 0 and 1 are ComboBoxEdit.

NB: I populate ComboBoxEdit in Col 1 using the result of comboBoxEdit in col 0.

My problem is that the items in comboboxEdit Col 1 in all rows are always based on the comboxBoxEdit Col 0 that exist in the last row. In other words I have always the same items in comboBoxEdit 1 in all rows.

How Can I achieve my aim.

Below my code:

MyView.xaml

<dxg:GridControl x:Name = "FilterGridControl" AutoGenerateColumns = "AddNew" ItemsSource = "{Binding Path=FilterList, Mode=TwoWay}" EnableSmartColumnsGeneration = "True" SelectionMode = "Row" SelectedItems = "{Binding SelectedFilter, Mode=TwoWay}">
<dxg:GridControl.Columns>
    <dxg:GridColumn Header = "Table" FieldName = "Table" HorizontalHeaderContentAlignment = "Center">
        <dxg:GridColumn.CellTemplate>
            <DataTemplate>
                <dxe:ComboBoxEdit x:Name = "PART_Editor" IsTextEditable = "False" ItemsSource = "{Binding DataContext.FilterTables, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" SelectedItem = "{Binding DataContext.SelectedFilterTables, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"></dxe:ComboBoxEdit>
            </DataTemplate>
        </dxg:GridColumn.CellTemplate>
    </dxg:GridColumn>
    <dxg:GridColumn Header = "Table Field" FieldName = "TableField" HorizontalHeaderContentAlignment = "Center" SortOrder = "Ascending" SortIndex = "0">
        <dxg:GridColumn.CellTemplate>
            <DataTemplate>
                <dxe:ComboBoxEdit x:Name = "PART_Editor" IsTextEditable = "False" ItemsSource = "{Binding DataContext.FilterColumns, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" ValueMember = "Name" DisplayMember = "Name" EditValue = "{Binding DataContext.SelectedFilterColumns, Mode=TwoWay,  RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"></dxe:ComboBoxEdit>
            </DataTemplate>
        </dxg:GridColumn.CellTemplate>
    </dxg:GridColumn>
    <dxg:GridColumn Header = "Name" FieldName = "Name" HorizontalHeaderContentAlignment = "Center">
        <dxg:GridColumn.EditSettings>
            <dxe:ComboBoxEditSettings IsTextEditable = "False" ItemsSource = "{ Binding EnumNameFilter}"></dxe:ComboBoxEditSettings>
        </dxg:GridColumn.EditSettings>
    </dxg:GridColumn>
    <dxg:GridColumn FieldName = "Value" HorizontalHeaderContentAlignment = "Center"/>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
    <dxg:TableView Name = "view" AllowPerPixelScrolling = "False" ShowTotalSummary = "True">
        <i:Interaction.Behaviors>
            <utilities:FocusNullRowBehavior/>
        </i:Interaction.Behaviors>
    </dxg:TableView>
</dxg:GridControl.View>

MyViewModel.cs:

public string SelectedFilterTables {
    get {
        return _selectedFilterTables;
    }
    set {
       this._selectedFilterTables = value;
       InitialiseFilterColumns();
    }

}

 public void InitialiseFilterColumns() {
    if (_selectedFilterTables != null) {
        _selectedFilter = new FilterDefinition();
        _selectedTable = null;
        _selectedFilter.TableField = null;
        _selectedFilter.Value = null;
        _filterColumns = null;
        _selectedTable = _tables.First(x = > x.Name == _selectedFilterTables);
        _filterColumns = new ObservableCollection < Column > (_selectedTable.Columns.ToList());
        OnPropertyChanged("FilterColumns");
    }
 }

Thank you in advance.

1
What have you accomplished so far? - netaholic

1 Answers

0
votes

It's unclear for me what is the problem. I suggest you create property in your VM like:

public IEnumerable<FilterColumns> FilterColumnsCollection
{
    get { return FilterList.LastOrDefault().FilterColumnsCollection} set {}
}