Я хотел бы создать целую строку ComboBoxes
в DataGrid
.Я добился определенного прогресса в следующем:
// Declare it
private DataGridComboBoxColumn CreateCustomComboBoxDataSouce(string ColumnName)
{
string[] data = { "Date", "LEInt", "String" };
DataGridComboBoxColumn dgCmbCol = new DataGridComboBoxColumn();
dgCmbCol.Header = ColumnName;
dgCmbCol.ItemsSource = data;
return dgCmbCol;
}
// Later somewhere you can add this to create 20 columns:
for (int i = 0; i < 20; i++)
{
DataGridComboBoxColumn newColumn = CreateCustomComboBoxDataSouce("Column-" +i);
}
// Sadly nothing is shown unless you manually specify a new row and an
// extra column as done here below, but then you get an extra column.
DataTable table = new DataTable();
table.Columns.Add("|", typeof(string));
table.Rows.Add("");
DataGridCombo.DataContext = table;
XAML сведен к минимуму:
<DataGrid x:Name="DataGridCombo" ItemsSource="{Binding}" Margin="0,0,0,0" />
Есть ли способ установить значение по умолчанию SelectedValue
для каждого ComboBox
?В моем цикле for
у меня есть доступ к нужной настройке.Кроме того, есть ли способ показать это без добавления дополнительного столбца?Эта DataGrid выровнена с другим DataGrid
, у которого не будет этого дополнительного столбца.