I'm wondering how you can set the selected element of a gridviewcomboboxcolumn.
As a bit of a foreword: I'm using the column with autocomplete mode in order to have autocomplete functionality, but I also want to add new elements to the list. It worked so far without a hitch EXCEPT for one situation:
I already have:
T1
T12
T123
In the data source.
Then when I have for example T12 selected and do backspace to select T1 I've got the problem that I need to manually click on T1 in the list AS there is no selection of T1 as there are multiple possibilities shown. Thus when I leave the editor mode without manually selecting T1 I get T12 as selected item.
I want to change this behaviour in such a way that the first found item is pre selected (always). (regardless if it is a new element or a changed to element so to say)
Currently I've already added a custom handler for the cellendedit to add the new value to the list:
private void MainFormGridView_CellEndEdit(object Sender, GridViewCellEventArgs eventArgs)
{
var virtualizedCurrentCell = ((Telerik.WinControls.UI.GridVirtualizedCellElement)(currentCell));
var currentGridviewComboBoxColumn = ((Telerik.WinControls.UI.GridViewComboBoxColumn)(virtualizedCurrentCell.Data));
if (((List<string>)currentGridviewComboBoxColumn.DataSource).IndexOf((string)currentCell.Value) > -1)
{
foundValueInList = true;
}
if (!foundValueInList)
{
((List<string>)currentGridviewComboBoxColumn.DataSource).Add((string)currentCell.Value);
}
}
The column itself is created in this way (bnefore being added to the gridview it is a part of:
GridViewComboBoxColumn newColumn;
newColumn = new GridViewComboBoxColumn();
((GridViewComboBoxColumn)newColumn).DataSource = (from c in entity.myOffer
orderby c.customer
where c.customer!= null
select c.customer)
.Distinct()
.ToList();
((GridViewComboBoxColumn)newColumn).DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown;
((GridViewComboBoxColumn)newColumn).AutoCompleteMode = AutoCompleteMode.SuggestAppend;
newColumn.FieldName = "customer";
newColumn.Name = "customer";
newColumn.HeaderText = "Customer";
newColumn.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
newColumn.Width = 100;
listOfColumns.Add(newColumn);
this.MainFormGridView.Columns.Add(newColumn);
So the question is there what can I do to select specific items in the dropdownlist AND is the CellEndEdit the correct location for that (as I suspect)?