Я хочу создать таблицу, в которую я могу динамически добавлять строки и столбцы, имеющие тип textbox или вводимые пользователем.
Затем я попытался использовать таблицы, но теперь я могу управлять только строками, а не столбцами.
table1 = new Table();
TextBox tbx = new TextBox();
TableRow row = new TableRow();
trg1.Rows.Add(row);
Paragraph para = new Paragraph();
para.Inlines.Add(tbx);
TableCell cell = new TableCell(para);
row.Cells.Add(cell);
Я пытался сделать это на DataGrid в wpf, но я могу контролировать только номер столбца, а не строки.
myGrid.Columns.Clear();
ObservableCollection<EmptyCell> collection = new ObservableCollection<EmptyCell>();
for (int i = 0; i < 4; i++) {
DataGridTemplateColumn dtg = new DataGridTemplateColumn();
dtg.CanUserResize = true;
dtg.IsReadOnly = false;
dtg.CellTemplate = getDataTemplate();
myGrid.CanUserAddRows = true;
myGrid.ItemsSource = collection;
myGrid.Columns.Add(dtg);
}
}
private static DataTemplate getDataTemplate()
{
DataTemplate template = new DataTemplate();
FrameworkElementFactory factory = new FrameworkElementFactory(typeof(TextBox));
factory.SetValue(TextBox.TextAlignmentProperty, TextAlignment.Right);
template.VisualTree = factory;
return template;
}