I got a DataGrid that is bound to an object PlacementData (PD). PD has a property "P_Unit".
public class PlacementData
{
public bool PIsChecked { get; set; }
public string PlacementHeader { get; set; }
public string P_NumberOfCases { get; set; }
public int P_Value1 { get; set; }
public int P_Value2 { get; set; }
public int P_Value3 { get; set; }
public int P_Value4 { get; set; }
public int P_Value5 { get; set; }
public string P_Unit { get; set; }
}
In my DataGrid I added a Combobox in DataTemplateColumn.
<DataGridTemplateColumn x:Name="UnitColumn1" Header="Unit" MinWidth="80" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox Text="{Binding P_Unit}">
<ComboBoxItem Content="kg/m3" IsSelected="True"/>
<ComboBoxItem Content="gm/cm3"/>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
On start of the window, I set the itemsource with 4 rows with headers added.
private List<PlacementData> datagrid1CollectionData()
{
List<PlacementData> authors = new List<PlacementData>();
authors.Add(new PlacementData()
{
PlacementHeader = "Based On Injection Rate",
});
authors.Add(new PlacementData()
{
PlacementHeader = "Based On Viscosity"
});
authors.Add(new PlacementData()
{
PlacementHeader = "Based On Sheer Thinning"
});
authors.Add(new PlacementData()
{
PlacementHeader = "k"
});
return authors;
}
dataGrid1.ItemsSource = datagrid1CollectionData();
My each row need different values for Unit combo box. For eg., 1 row needs "kg, gm", 2nd needs "meter, cm, feet", 3rd needs "ltr, ml, ton", & 4th needs it to be blank.
How do I set these values ? I think on each row creation, I can create a List and assign that as itemsource to the checkbox. But how is this possible in the above code. Checkbox Itemsource for each row of checkbox ???