本文介绍了如何在运行时在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 C#datagrid中添加datagridcomboboxcolumn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 12:33