将组合框插入到动态表中

本文关键字:动态 插入 组合 | 更新日期: 2023-09-27 18:35:56

我正在尝试在动态表中创建一个组合框,但我不确定我在这里做错了什么。

        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()));

用户输入数据后,如何将具有新组合框的新行添加到表中?

将组合框插入到动态表中

正如错误已经指出的那样,没有TableCell构造函数直接接受UIElement作为其参数。您需要使用BlockUIContainer包装它:

currentRow.Cells.Add(new TableCell(new BlockUIContainer(cbox)));
相关文章: