我正在尝试在动态表中创建一个 ComboBox,但我不确定我在这里做错了什么。
table1.RowGroups[0].Rows.Add(new TableRow());
currentRow = table1.RowGroups[0].Rows[1];
ComboBox cbox=new ComboBox();
System.Windows.Controls.ComboBoxItem cboxitem=new System.Windows.Controls.ComboBoxItem();
cboxitem.Content="stuff";
cbox.Items.Add(cboxitem);
currentRow.Cells.Add(new TableCell(cbox)); //Error 1 The best overloaded method match for 'System.Windows.Documents.TableCell.TableCell(System.Windows.Documents.Block)' has some invalid arguments
currentRow.Cells.Add(new NumericUpDown()));
一旦用户输入数据,我如何向表格中添加带有新组合框的新行?
最佳答案
如错误所述,不存在直接接受 UIElement
作为其参数的 TableCell
构造函数。您需要使用 BlockUIContainer
包装它:
currentRow.Cells.Add(new TableCell(new BlockUIContainer(cbox)));
关于c# - 将 ComboBox 插入动态表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27751745/