this.sfdatagrid.EditTrigger = EditTrigger.OnDoubleTap;
this.sfdatagrid.CellRenderers.Remove("ComboBox");
this.sfdatagrid.CellRenderers.Add("ComboBox", new GridCellComboBoxRendererExt());
public class GridCellComboBoxRendererExt : GridCellComboBoxRenderer
{
protected override void OnEditElementLoaded(object sender, System.Windows.RoutedEventArgs e)
{
base.OnEditElementLoaded(sender, e);
var combobox = sender as ComboBox;
combobox.IsDropDownOpen = true;
}
} |
this.sfdatagrid.CellTapped += sfdatagrid_CellTapped;
void sfdatagrid_CellTapped(object sender, GridCellTappedEventArgs e)
{
if (sfdatagrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex != e.RowColumnIndex
&& sfdatagrid.SelectionController.CurrentCellManager.CurrentCell.Renderer is GridCellComboBoxRendererExt)
{
var comboBox = (sfdatagrid.SelectionController.CurrentCellManager.CurrentCell.Renderer as GridCellComboBoxRendererExt).CurrentCellRendererElement as ComboBox;
if (comboBox != null)
{
//Activate the tapped cell to end the editing of the combo box cell.
sfdatagrid.MoveCurrentCell(e.RowColumnIndex);
}
}
} |
private void DataGrid_CurrentCellEndEdit(object sender, CurrentCellEndEditEventArgs e)
{
var sfDataGrid = sender as SfDataGrid;
if (sfDataGrid.CurrentColumn.MappingName != "ShipCountry")
return;
var datarow = dataGrid.RowGenerator.Items.FirstOrDefault(dr => dr.RowIndex == e.RowColumnIndex.RowIndex);
datarow.Element.DataContext = null;
dataGrid.UpdateDataRow(e.RowColumnIndex.RowIndex);
} |