如何在运行时在WPF C#datagrid中添加datagridcomboboxcolumn? [英] How to add datagridcomboboxcolumn in WPF C# datagrid at runtime ?

查看:151
本文介绍了如何在运行时在WPF C#datagrid中添加datagridcomboboxcolumn?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用在运行时在wpf DataGrid中添加DataGridComboBoxColumn。

用户指定运行时的总列数。根据运行时输入,应该动态创建colunm。在这里,我无法添加新行。



我尝试过:



XAML:

How a use Add DataGridComboBoxColumn in wpf DataGrid at Runtime.
User Specify total number of columns at runtime. According to runtime input the colunm should be created dynamically. Here i'm not able to add new row.

What I have tried:

XAML:

DataGrid x:name="dataGrid"



c#


c#

DataGridTextColumn so = new DataGridTextColumn();
so.Header = "S.No";
dataGrid.Columns.Add(so);

DataGridTextColumn name= new DataGridTextColumn();
name.Header = " Name";
dataGrid.Columns.Add(name);

DataGridColumn age= new DataGridTextColumn();
age.Header = "Age";
dataGrid.Columns.Add(age);

for (int i = 1; i <= p; i++)
{
    DataGridComboBoxColumn ss = new DataGridComboBoxColumn();
    ss.Header = i;
    List<string> list = new List<string>();
    list.Add("Item 1");
    list.Add("Item 2");
    ss.ItemsSource = list;
    ss.Width = 50;
    ss.EditingElementStyle = style;

    dataGrid.Columns.Add(ss);
}

推荐答案

您的代码对我来说很好,但是,在选择之后,所选项目不是当前单元格中的设置。按照以下链接,这是在wpf数据网格中添加组合框列的最佳方法。

WPF中DataGrid中的ComboBox [ ^ ]
Hi, your code is working fine for me, However, after the selection, the selected item is not sets in the current cell. Follow the below link, this is the best way to add combobox column in wpf datagrid.
ComboBox in DataGrid in WPF[^]


这篇关于如何在运行时在WPF C#datagrid中添加datagridcomboboxcolumn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆