WPF在Devexpress的gridcontrol中ComboBox绑定数据

 

 

 

 

Use the CellTemplate property to define a template that specifies the visualization of column cells. The binding source for the CellTemplate template is represented by the EditGridCellData class.

The EditGridCellData class has the Value property that provides access to the cell editable value. Use the RowData.Row property to access a row's data object property: {Binding RowData.Row.[YourPropertyName]}

The code sample belows shows how to use a custom ComboBoxEdit within grid cells:

 

其中{Binding RowData.Row.[YourPropertyName]} 绑定可以更换为其他的:

        <ObjectDataProvider x:Key="SpectrometerState" MethodName="GetValues" ObjectType="{x:Type core:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type Type="Infrastructure:SpectrometerState"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

//然后再需要的地方添加绑定 ,x:Name=“Part_Editor”是必须的

<dxg:GridColumn.CellTemplate>
                            <DataTemplate>
                                <dxe:ComboBoxEdit x:Name="PART_Editor" ItemsSource="{Binding Source={StaticResource SpectrometerState}}"/>
                            </DataTemplate>
          </dxg:GridColumn.CellTemplate>

以下是官网提供的代码

public ObservableCollection<CountryCities> Items {
    get {
        if(this._Items == null) {
            this._Items = new ObservableCollection<CountryCities>();

            CountryCities usa = new CountryCities() {
                Country = "USA",
                Cities = new List<string> { "Washington, D.C.", "New York", "Los Angeles", "Las Vegas" },
                City = "Los Angeles"
            };
            this._Items.Add(usa);

            CountryCities germany = new CountryCities() {
                Country = "Germany",
                Cities = new List<string> { "Berlin", "Munich", "Frankfurt" },
                City = "Munich"
            };
            this._Items.Add(germany);

            CountryCities russia = new CountryCities() {
                Country = "Russia",
                Cities = new List<string> { "Moscow", "Saint-Petersburg" },
                City = "Moscow"
            };
            this._Items.Add(russia);
        }
        return this._Items;
    }
}
<dxg:GridControl AutoGenerateColumns="AddNew" EnableSmartColumnsGeneration="True" ItemsSource="{Binding Items}">
    <dxg:GridColumn FieldName="Country"/>
    <dxg:GridColumn FieldName="City">
        <dxg:GridColumn.CellTemplate>
            <DataTemplate>
                <dxe:ComboBoxEdit x:Name="PART_Editor" ItemsSource="{Binding RowData.Row.Cities}"/>
            </DataTemplate>
        </dxg:GridColumn.CellTemplate>
    </dxg:GridColumn>
    <dxg:GridControl.View>
        <dxg:TableView/>
    </dxg:GridControl.View>
</dxg:GridControl>


 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值