AUTHOR: Dimitar Karamfilov
DATE POSTED: July 28, 2015
Problem
By default you can only select values from the drop down with GridComboBoxColumn. Sometimes you may need to provide the user with predefined values and allow him/her to use custom ones as well.
Solution Figure1. The final result.
To achieve this functionality, you should create a custom editor which returns the text of the combo box editor. In addition, you should create a custom cell element and override the SetContent method. This is necessary because by default the cell is looking for the proper value in the editor data source.
public
class
MyRadDropDownListEditor : RadDropDownListEditor
{
override
object
Value
get
RadDropDownListElement editor =
this
.EditorElement
as
RadDropDownListElement;
if
(editor.SelectedItem !=
null
)
(!
string
.IsNullOrEmpty(editor.ValueMember))
return
editor.SelectedItem.Value;
}
editor.SelectedItem.Text;
editor.Text;
set
base
.Value = value;
MyCombBoxCellElement : GridComboBoxCellElement
MyCombBoxCellElement(GridViewColumn col, GridRowElement row) :
(col, row)
void
SetContent()
SetContentCore(
.Value);
Public
Class
MyRadDropDownListEditor
Inherits
RadDropDownListEditor
Overrides
Property
Value()
As
Object
Get
Dim
editor
RadDropDownListElement = TryCast(
Me
.EditorElement, RadDropDownListElement)
If
editor.SelectedItem IsNot
Nothing
Then
Not
String
.IsNullOrEmpty(editor.ValueMember)
Return
editor.SelectedItem.Value
End
editor.SelectedItem.Text
editor.Text
Set
(
ByVal
value
MyBase
.Value = value
MyCombBoxCellElement
GridComboBoxCellElement
Sub
New
col
GridViewColumn,
row
GridRowElement)
.
.Value)
radGridView1_CreateCell(
sender, GridViewCreateCellEventArgs e)
(e.CellType ==
typeof
(GridComboBoxCellElement))
e.CellElement =
new
MyCombBoxCellElement(e.Column
GridViewDataColumn, e.Row);
radGridView1_EditorRequired(
sender, EditorRequiredEventArgs e)
(e.EditorType ==
(RadDropDownListEditor))
e.EditorType =
(MyRadDropDownListEditor);
[VB]
Private
sender
,
e
GridViewCreateCellEventArgs)
e.CellType
Is
GetType
(GridComboBoxCellElement)
MyCombBoxCellElement(TryCast(e.Column, GridViewDataColumn), e.Row)
EditorRequiredEventArgs)
e.EditorType
(RadDropDownListEditor)
(MyRadDropDownListEditor)
Resources Buy Try