patterncsharpMinor
Populating a datagrid of comboboxes
Viewed 0 times
datagridpopulatingcomboboxes
Problem
The goal is to have a
Here's the XAML to create said grid:
Here's the code behind for the binding:
{
public ObservableCollection Product { get; set; }
public ObservableCollection Units { get; set; }
public ObservableCollection Amount { get; set; }
public MudMaterial()
{
Product = new ObservableCollection() { " ",
"Gel",
"Barrite",
"Detergent",
"Soap",
"X Gel",
"Bentonite",};
Units = new ObservableCollection() {" ",
"20 lb bag",
"40 lb bag",
"50 lb bag",
"80 lb bag",
"1 gal",
"2 gal",
"3 gal",};
Amount = new ObservableCollection() {" ",
"1",
"2",
"3",
"4",
DataGrid of comboboxes, 10 rows, 3 columns.Here's the XAML to create said grid:
Here's the code behind for the binding:
private void SetGrid()
{
var materialList = new List();
var newMaterial = new MudMaterial();
for (var i = 0; i
The MudMaterial Class:
class MudMaterial{
public ObservableCollection Product { get; set; }
public ObservableCollection Units { get; set; }
public ObservableCollection Amount { get; set; }
public MudMaterial()
{
Product = new ObservableCollection() { " ",
"Gel",
"Barrite",
"Detergent",
"Soap",
"X Gel",
"Bentonite",};
Units = new ObservableCollection() {" ",
"20 lb bag",
"40 lb bag",
"50 lb bag",
"80 lb bag",
"1 gal",
"2 gal",
"3 gal",};
Amount = new ObservableCollection() {" ",
"1",
"2",
"3",
"4",
Solution
If your items in the ComboBox are static, you don't need binding at all.
Grapes
Apples
Oranges
Code Snippets
<DataGridTemplateColumn Header="Product">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox>
<ComboBoxItem>Grapes</ComboBoxItem>
<ComboBoxItem>Apples</ComboBoxItem>
<ComboBoxItem>Oranges</ComboBoxItem>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>Context
StackExchange Code Review Q#29507, answer score: 3
Revisions (0)
No revisions yet.