Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > WPF и Silverlight > Multiple binding in DataGrid


Автор: Larrr 5.1.2009, 15:49
Привет, вопрос такой

У меня есть DataGrid, который тянет данные для столбцов из ресурса PropertiesTable. В одном из столбиков у меня находится ComboBox (он же DropDownList), в который надо набиндовать список совсем из другого ресурса, а из исходного ресурса PropertiesTable взять то, какой элемент установить в качестве Selected. Как это сделать?



Код

<enf:DataGrid Name="TemplateProperties" ItemsSource="{Binding PropertiesTable}" AutoGenerateColumns="False" CanUserAddRows="False" >
            <enf:DataGrid.Columns>
                <enf:DataGridTextColumn Header="Property name" IsReadOnly="False" Binding="{Binding Name}"></enf:DataGridTextColumn>
                <enf:DataGridComboBoxColumn Header="Property type" IsReadOnly="False" !!!Тут надо набиндить список и выбранный элемент!!! ></enf:DataGridComboBoxColumn>
                <enf:DataGridCheckBoxColumn Header="Reqiured?" IsReadOnly="False" Binding="{Binding Required}"></enf:DataGridCheckBoxColumn>
                <enf:DataGridTextColumn Header="Context Help" IsReadOnly="False" Binding="{Binding Description}"></enf:DataGridTextColumn>
                <enf:DataGridTemplateColumn Header="Delete property">
                    <enf:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Name="DeleteProperty" Click="DeleteProperty_Click" CommandParameter="{Binding Path='Name'}" >Delete property</Button>
                        </DataTemplate>
                    </enf:DataGridTemplateColumn.CellTemplate>
                </enf:DataGridTemplateColumn>
            </enf:DataGrid.Columns>
        </enf:DataGrid>


Автор: Partizan 5.1.2009, 18:56
Larrr, ItemsSource у DataGridComboBoxColumn есть? Ну или любое другое свойство, отвечающее за коллекцию айтемов?

Автор: Larrr 5.1.2009, 19:04
Partizan, свойство есть, но оно не работает. Когда я делаю так

Код

<enf:DataGridComboBoxColumn Header="Property type" IsReadOnly="False" ItemsSource="{Binding DataTypes}" SelectedValuePath="Value" DisplayMemberPath="Text"></enf:DataGridComboBoxColumn>


комбобокс остается пустым, с другой стороны вне датагрида есть другой комбобокс, почти такой же

Код

 <ComboBox Name="Test" ItemsSource="{Binding DataTypes}" SelectedValuePath="Value" DisplayMemberPath="Text"><ComboBox>


который наполняется данными без проблем.

Автор: Partizan 5.1.2009, 19:11
Larrr, DataContext у DataGrid и нормально заполняющегося ComboBox-а скорее всего разный...

попробуйте так:

Код

<enf:DataGridComboBoxColumn Header="Property type" IsReadOnly="False" ItemsSource="{Binding ElementName=.... , Path=DataTypes}" SelectedValuePath="Value" DisplayMemberPath="Text"/>


вместо точек укажите имя объекта, доступного в xaml и содержащего свойство DataTypes

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)