I'm extending a GridViewComboBoxColumn, setting IsComboBoxEditable to true, and trying to provide code to add typed text as items into the ItemsSource collection.
I hooked the CellEditEnded event of the GridView and added some test code to play with this idea:
private void TestGrid_CellEditEnded(object sender, Telerik.Windows.Controls.GridViewCellEditEndedEventArgs e)
{
var comboBoxColumn = e.Cell.Column as Telerik.Windows.Controls.GridViewComboBoxColumn;
// only continue if its a cell for the column we're interested in
if ((comboBoxColumn == null) || (comboBoxColumn.UniqueName != "Lookup"))
return;
// get back the object used to represent the row
var gridItem = e.Cell.DataContext as GridItem;
// only continue if the text typed is not in the list
if (gridItem.SelectedLookupItem != null)
return;
var cellComboBox = (RadComboBox)e.EditingElement;
var lookupItemCollection = cellComboBox.ItemsSource as ObservableCollection<LookupItem>;
var newItem = new LookupItem() { Name = cellComboBox.Text };
lookupItemCollection.Add(newItem);
//set the typed item as the selected item
gridItem.SelectedLookupItem = newItem;
}
Works great. Now I want to move that code into my extended GridViewComboBoxColumn. How could I hook/override the CellEditEnded from inside the extended column?
I hooked the CellEditEnded event of the GridView and added some test code to play with this idea:
private void TestGrid_CellEditEnded(object sender, Telerik.Windows.Controls.GridViewCellEditEndedEventArgs e)
{
var comboBoxColumn = e.Cell.Column as Telerik.Windows.Controls.GridViewComboBoxColumn;
// only continue if its a cell for the column we're interested in
if ((comboBoxColumn == null) || (comboBoxColumn.UniqueName != "Lookup"))
return;
// get back the object used to represent the row
var gridItem = e.Cell.DataContext as GridItem;
// only continue if the text typed is not in the list
if (gridItem.SelectedLookupItem != null)
return;
var cellComboBox = (RadComboBox)e.EditingElement;
var lookupItemCollection = cellComboBox.ItemsSource as ObservableCollection<LookupItem>;
var newItem = new LookupItem() { Name = cellComboBox.Text };
lookupItemCollection.Add(newItem);
//set the typed item as the selected item
gridItem.SelectedLookupItem = newItem;
}
Works great. Now I want to move that code into my extended GridViewComboBoxColumn. How could I hook/override the CellEditEnded from inside the extended column?