this.Grid.CellRenderers.Remove("MultiColumnDropDown");
this.Grid.CellRenderers.Add("MultiColumnDropDown", new MultiDropDownRenderer());
public class MultiDropDownRenderer: GridCellMultiColumnDropDownRenderer
{
protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
var multiDropDown = (this.CurrentCellRendererElement as SfMultiColumnDropDownControl);
var textBox = multiDropDown.GetType().GetProperty("Editor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(multiDropDown);
var newValue = textBox != null ? (textBox as TextBox).Text : null;
var underlyingItems = (this.DataGrid.DataContext as ViewModel).ProductList;
if (underlyingItems != null)
{
bool newRecord = underlyingItems.Any(x => x.Code == newValue.ToString());
if (!newRecord)
{
underlyingItems.Add(new ProductInfo() { Code = newValue.ToString(), ID = underlyingItems.Count + 1 });
multiDropDown.SelectedItem = underlyingItems.Last();
}
}
}
return base.ShouldGridTryToHandleKeyDown(e);
}
} |
very very helpful!
Thank you!