Как связать список со списком, который находится в подклассе источника данных гридов данных? - PullRequest
1 голос
/ 21 февраля 2011

Это мой код для моей DxGrid:

<dxg:GridControl x:Name="gridControlItemsDistinct" 
                             VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                             Height="Auto" Width="Auto"
                             AutoPopulateColumns="False"
                             DataSource="{Binding Path=ChaseListHelperClassItemsList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<dxg:GridControl.Columns>
    <dxg:GridColumn FieldName="CreativeContactID" Header="Creative Contact Name" Width="90" FilterPopupMode="CheckedList" AllowEditing="True">
        <dxg:GridColumn.EditSettings>
            <dxe:ComboBoxEditSettings Name="cboCreativeContact"
                            DisplayMember="ContactName" 
                            AutoComplete="True" 
                            ValueMember="ContactID" 
                            ItemsSource="{Binding Path=Data.CreativeAgContactList, UpdateSourceTrigger=PropertyChanged}" />
        </dxg:GridColumn.EditSettings>
        <dxg:GridColumn.CellStyle>
            <Style TargetType="{x:Type dxg:CellContentPresenter}">
                <Setter Property="Background" Value="#FFE8F2F3" />
                <Setter Property="TextBlock.Foreground" Value="Black" />
            </Style>
        </dxg:GridColumn.CellStyle>
    </dxg:GridColumn>
</dxg:GridControl.Columns>

Как видите, моя сетка привязывается к ChaseListHelperClassItemsList:

public List<CreateChaseListHelperClass> ChaseListHelperClassItemsList
    {
        get 
        {
            return chaseListHelperClassItemsList; 
        }
        set
        {
            chaseListHelperClassItemsList = value;
            OnPropertyChanged("ChaseListHelperClassItemsList");
        }
    }

CreateChaseListHelperClass:

    public class CreateChaseListHelperClass
    {
        private int creativeContactID;

        public int CreativeContactID
        {
            get;
            set;
        }

        public IQueryable<Contacts> CreativeAgContactList
        {
            get;
        }
    }

Мой вопрос: как мне связать cboCreativeContact ItemSource со списком внутри моего CreateChaseListHelperClass, CreativeAgContactList.

Моя текущая привязка выглядит следующим образом:

ItemsSource="{Binding Path=Data.CreativeAgContactList, UpdateSourceTrigger=PropertyChanged}"

Мой DataContext установлен в моем представлении:

DataContact = ChaseListViewModel

Итак, структура

ChaseListViewModel-CreateChaseListHelperClassList-CreativeAgContactList

Я хочу установить CreateAgContactList какItemSource на моем ComboBox

1 Ответ

1 голос
/ 21 февраля 2011

Вот и мы. Используйте шаблон ячейки:

<dxg:GridColumn FieldName="CreativeAgContactID" Header="Creative Contact Name" Width="90" FilterPopupMode="CheckedList" AllowEditing="True">
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <dxe:ComboBoxEdit Name="cboCreativeContact" 
                                              DisplayMember="ContactName"
                                              ValueMember="ContactID"
                                              AutoComplete="True" 
                                              EditValue="{Binding Path=ContactID, UpdateSourceTrigger=PropertyChanged}"
                                              ItemsSource="{Binding Path=Data.CreativeAgContactList, UpdateSourceTrigger=PropertyChanged}">                                    
                            </dxe:ComboBoxEdit>
                        </DataTemplate>
                    </dxg:GridColumn.CellTemplate>
                    <dxg:GridColumn.CellStyle>
                        <Style TargetType="{x:Type dxg:CellContentPresenter}">
                            <Setter Property="Background" Value="#FFE8F2F3" />
                            <Setter Property="TextBlock.Foreground" Value="Black" />
                        </Style>
                    </dxg:GridColumn.CellStyle>
                </dxg:GridColumn>
...