xaml code inside DataGrid
- <DataGridTemplateColumn Header="Unit" Width="65"> <DataGridTemplateColumn.CellTemplate>
- <DataTemplate>
- <my:PLGDComboBox Height="23" ItemsSource="{Binding Path=SaveCls.PurDtlMastCol[RowIndx].ItemUnitCol,RelativeSource={RelativeSource AncestorType={x:Type invname:MasterForm},AncestorLevel=1,Mode=FindAncestor},UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" SelectedValue="{Binding Path=PurUnit.UnitId,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" DisplayMemberPath="UnitName" SelectedValuePath="UnitId"/> </DataTemplate > </DataGridTemplateColumn.CellTemplate>
View Model Code:
- if (dtUnit.Rows.Count > 0)
- {
- this.SaveCls.PurDtlMastCol[rowIndex].ItemUnitCol = new PL21000DCol();
- foreach (DataRow dr in dtUnit.Rows)
- {
- this.SaveCls.PurDtlMastCol[rowIndex].ItemUnitCol.Add(new PL21000D()
- {
- UnitId = PLWM.Utils.CnvToInt64(dr["unit_id"]), UnitName = PLWM.Utils.CnvToStr(dr["unit_name"]) });
- }
- }