I need to use dropdownlist as RadGridView editor
and I have look into this
https://docs.telerik.com/devtools/winforms/controls/dropdown-listcontrol-and-checkeddropdownlist/checkeddropdownlist/how-to/use-as-radgridview-editor
In the sample above,it bound a datasource to the dropdownlist editor,but only handle the display text and control value by overiding the "Value" property.
If I want to bind a datasource with valuemember and displaymember,how to handle them properly?What I expect is to let user choose with the displaymember and valuemember can be saved according to what user choose just like the normal checkeddropdownlist control.
3 Answers, 1 is accepted
I would like to note that RadGridView offers a GridViewComboBoxColumn. It displays a set of predefined text values in a drop down list. This column type is typically used to provide a lookup into some set of relatively static values. It allows you to specify DisplayMember and ValueMember properties out of the box. If you don't need to provide multiple selection to the end users, feel free to use the GridViewComboBoxColumn.
As to the RadCheckedDropDownListElement as an editor, you can customize the referred example as it is demonstrated below in order to have a ValueMember for the items in the drop down:
BindingList<Item> columnData;
BindingList<MyPart> datasource;
public
RadForm1()
{
InitializeComponent();
columnData =
new
BindingList<Item>();
datasource =
new
BindingList<MyPart>();
for
(
int
i = 0; i < 5; i++)
{
datasource.Add(
new
MyPart(
"Part "
+ i +
";Part "
+ (i + 1) +
";"
));
}
radGridView1.AutoGenerateColumns =
false
;
radGridView1.DataSource = datasource;
GridViewTextBoxColumn checkedDropDownListColumn =
new
GridViewTextBoxColumn();
checkedDropDownListColumn.FieldName =
"CurrentParts"
;
checkedDropDownListColumn.Width = 200;
this
.radGridView1.Columns.Add(checkedDropDownListColumn);
for
(
int
i = 0; i < 10; i++)
{
columnData.Add(
new
Item(i,
"Part "
+ i));
}
this
.radGridView1.EditorRequired += radGridView1_EditorRequired;
}
void
radGridView1_EditorRequired(
object
sender, EditorRequiredEventArgs e)
{
if
(
this
.radGridView1.CurrentColumn.Index == 0)
{
RadCheckedDropDownListElement editor =
new
GridViewCheckedDropDownListEditor();
editor.DataSource =
this
.columnData;
editor.DisplayMember =
"Name"
;
editor.ValueMember =
"Id"
;
e.Editor = editor;
}
}
public
class
GridViewCheckedDropDownListEditor : RadCheckedDropDownListElement
{
public
override
object
Value
{
get
{
return
this
.Text;
}
set
{
this
.Text = value.ToString();
}
}
}
public
class
MyPart
{
public
string
CurrentParts {
get
;
set
; }
public
MyPart(
string
currentParts)
{
this
.CurrentParts = currentParts;
}
}
public
class
Item
{
public
int
Id {
get
;
set
; }
public
string
Name {
get
;
set
; }
public
Item(
int
id,
string
name)
{
this
.Id = id;
this
.Name = name;
}
}
Note that most of the forum threads are reviewed by Telerik representatives and sometimes we address the questions asked by our customers in the forums as well. However, a post in the forum doesn't guarantee you a response from the Telerik support team. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.
Thank you for your understanding.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Thanks for the reply,Dess.
I've
tried the codes you show above,but it seems doesn't work.
For example ,when I check "Part 0""Part 1","Part 2" in row[0],the value of the cell in row[0] in the gridview is "Part 0;Part 1;Part 2;" which is the "list of the display text".But what I expect is after I checked "Part 0""Part 1","Part 2", a "list of the value" like "0;1;2" should be value of the cell in the gridview.
And now my solution is to customize the entire column according to https://www.telerik.com/support/kb/winforms/gridview/details/mutiselect-drop-down-list-column-in-radgridview
I've
changed the type of the column from
"int[]" to "string" and it works perfectly in my case.
This KB article is also a possible solution. However, it was recommended for the time (back in 2012) when the WinForms suite didn't offer RadCheckedDropDownList.
Now, we have such a control that supports checking multiple items. Hence, I would recommend you to use it. If you need to store the IDs in the cell values, you can simply use the CellFormatting event in RadGridView in order to control what text to be displayed in the cells (not the IDs). In addition, in the CellEditorInitialized it would be necessary to check the respective item in RadCheckedDropDownListElement considering the current cell's value.
Feel free to use this approach which suits your requirement best.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik