Hello,
Kindly find my explanation as below:
Step 1:
In Xaml, have the Combobox as Cell Editor in the Resources
<xcdg:CellEditor x:Key="statusEditor">
<xcdg:CellEditor.EditTemplate>
<DataTemplate>
<ComboBox BorderThickness="0"
x:Name="cmbStatus"
MinHeight="20"
VerticalContentAlignment="Top"
DisplayMemberPath="Enum_Value"
SelectedValuePath="Enum_ID"
Text="{xcdg:CellEditorBinding}"
FocusVisualStyle="{x:Null}"
Loaded="ComboBox_Loaded"
SelectionChanged="cmb_SelectionChanged">
<ComboBox.Resources>
<Style TargetType="Popup">
<Setter Property="TextElement.Foreground" Value="{DynamicResource
{x:Static SystemColors.WindowTextBrushKey}}" />
</Style>
</ComboBox.Resources>
</ComboBox>
</DataTemplate>
</xcdg:CellEditor.EditTemplate>
<xcdg:CellEditor.ActivationGestures>
<xcdg:TextInputActivationGesture/>
</xcdg:CellEditor.ActivationGestures>
</xcdg:CellEditor>
Step 2: Declare the Columns as you want to bind the combobox to the above cell editor
<xcdg:Column FieldName="Status" x:Key="colEntityStatus" Title="Status" CellEditor="{StaticResource statusEditor}" >
</xcdg:Column>
Now all you have to do in the .cs file:
Step 3
protected void ComboBox_Loaded(object sender, RoutedEventArgs e)
{
ComboBox cmb = sender as ComboBox;
if (cmb != null)
{
cmb.SelectionChanged += new SelectionChangedEventHandler(cmb_SelectionChanged);
cmb.ItemsSource = dt.DefaultView; //your itemssource
if (drdgCurrentItem != null)
cmb.SelectedValue = 123; //(Default value)
}
Step 4:
protected void cmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox cmb = sender as ComboBox;
if (cmb != null)
{
if (Convert.ToInt32(cmb.SelectedValue) > 0)
{
//you can make changes to the DataRowView which you are inserting or editing
if (drdgCurrentItem != null)
drdgCurrentItem["Entity_StatusID"] = cmb.SelectedValue;
}
Thanks,
Paras Sanghani
Nothing Is Impossible
Nothing Is Impossible