public
FrameworkElementFactory BindComboInDetail(string GridColumnName, string FieldName, string DisplayField, ref DataTable ComboData, bool IsComboEditable)
{
try
{
DataTemplate dtTemplate = new DataTemplate();
ComboBox cmb = new ComboBox();
FrameworkElementFactory fef = new FrameworkElementFactory(typeof(ComboBox));
Binding listBinding = new Binding();
Xceed.Wpf.DataGrid.Markup.
CellEditorBindingExtension cellEditorBinding = new Xceed.Wpf.DataGrid.Markup.CellEditorBindingExtension();
listBinding.Source = ComboData;
fef.SetValue(
ComboBox.NameProperty, "cmb" + GridColumnName);
fef.SetValue(
ComboBox.IsEditableProperty, IsComboEditable);
cellEditorBinding.NotifyOnSourceUpdated =
true;
cellEditorBinding.NotifyOnTargetUpdated =
true;
fef.SetValue(
ComboBox.SelectedValuePathProperty, FieldName);
fef.SetValue(
ComboBox.DisplayMemberPathProperty, DisplayField);
fef.SetValue(
ComboBox.SelectedValueProperty, cellEditorBinding.ProvideValue(null) as BindingBase);
fef.SetBinding(
ComboBox.ItemsSourceProperty, listBinding);
fef.SetValue(
ComboBox.ItemContainerStyleProperty, FindResource("cmbItem"));
dtTemplate.VisualTree = fef;
foreach (Xceed.Wpf.DataGrid.ColumnBase col in dgGrid.DetailConfigurations[0].Columns)
if (col.FieldName.ToString().ToLower().Equals(GridColumnName.ToLower()))
{
col.CellEditor =
new Xceed.Wpf.DataGrid.CellEditor();
col.CellEditor.EditTemplate = dtTemplate;
col.CellEditorDisplayConditions =
CellEditorDisplayConditions.Always;
col.CellContentTemplate = dtTemplate;
col.AutoFilterControlStyle = MainGridPanel.FindResource(
"textBlockDistinctValueItemTemplate") as Style;
break;
}
fef.RemoveHandler(
ComboBox.PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(Dropdown_PreviewMouseLeftButtonDown));
fef.AddHandler(
ComboBox.PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(Dropdown_PreviewMouseLeftButtonDown));
return fef;
}
catch (Exception ex)
{
ToolWindow.getException(ex, this);
}
return new FrameworkElementFactory();
}