【发布时间】:2014-10-25 12:12:27
【问题描述】:
我正在使用 WPF 应用程序。我需要使用一些属性动态创建按钮,并在 dataGridView 行中添加按钮。但是 Datatable 不包含 Button DataType 那么如何做到这一点 请有人帮助我提前谢谢。
这是我的代码:
DataTable NewDataTable = new DataTable();
for (int i = 0; i < Row * level; i++)
{
Button[] buttonArray = new Button[position];
string Col1 = "Rows";
string Col2 = "Levels";
for (int j = 0; j < position; j++)
{
if (j == 1)
{
Col1 = "Rows";
}
else if (j == 2)
{
Col2 = "Levels";
}
else
{
buttonArray[j] = new Button();
buttonArray[j].Content = "Postion " + j;
buttonArray[j].ToolTip = "Postion " + j;
}
}
NewDataTable.Rows.Add(Col1, Col2, buttonArray[j]);
}
代码背后
Dgrid.ItemsSource = NewDataGrid.DefaultView();
【问题讨论】:
-
好吧,如果“数据表不包含”某些内容,则创建一个包含所需数据的自定义对象集合并将其分配给
ItemsSource。无论如何,在 WPF 应用程序中很少有 DataTable 的位置。如需更多信息和示例,请查看MSDN-DataGrid。
标签: c# wpf c#-4.0 wpf-controls wpfdatagrid