|
Article relates to
|
RadControls for WinForms, Q2 2010 SP2
|
|
Created by
|
Nikolay Diyanov
|
|
Last modified
|
Sept 20, 2010
|
|
Last modified by
|
Alexander Georgiev, Telerik
|
INTRODUCTION
By default, the GridViewComboBoxColumn opens a RadDropDownListEditor which allows you to select a value, but the editor itself remains read-only. The purpose of this article is to demonstrate how you can add and remove items to the RadDropDownListEditor.
SOLUTION
You can find solutions in C# and VB.NET at the bottom of this article.

The current example demonstrates a custom editor which is bound to a collection of strings. The user can add strings/items to the custom editor by typing the value and then pressing the Enter key. The user can remove strings/items as well by a RadButtonElement which is assigned to each RadListVisualItem.
An example of implementing a custom editor is demonstrated in our
help documentation. In our case, we will inherit from the RadDropDownListEditor class:
As you can see in the code snippet above, we return an instance of a custom MyComboBoxEditorElement which descends from RadDropDownListElement. This element is the actual combobox which you see when you open the combo editor.
There are several key parts in the MyComboBoxEditorElement:
1. Adding Remove buttons to the RadListVisualItems.
This part adds Remove buttons to the items when the MyComboBoxEditorElement is loaded:
In the Click event of the RadButtonElement, we get the Data item from the respective RadListVisualItem and then remove it from the DataSource of the GridViewComboBoxColumn:
2. Checking if a typed value exists in the DataSource.
This part prevents a new string from entering in the DataSource if the same string already exists there:
3. Overriding the ProcessKeyDown method:
When the user presses the Enter key after a value is typed in the combo editor, we check if the item exists in the current DataSource collection. If it does not exist, we add it to the DataSource collection.
Last, but not least, here is how we setup our GridViewComboBoxColumn: