I have a data entry RadGridView bound to a collection of POCOs. It has some rather compiles editing requirements. On one particular row, there is a cell that requires the edit control to be a multi-selection combo box. On all other rows it requires a numeric entry. I created the column as a GridViewComboBoxColumn. and then tried to create a custom control to replace the standard editor using the EditorRequired event like this:
private void gvMatrix_EditorRequired(object sender, EditorRequiredEventArgs e)
{
if (gvMatrix.CurrentRow.Cells["Comparison"].Value.ToString() == "One of")
{
if (e.EditorType == typeof(CustomCheckedListBox))
e.EditorType = typeof(CustomCheckedListBox);
}
//Otherwise I need numeric entry
}
Then, I tried to create the custom control based on the example on the Telerik site (https://docs.telerik.com/devtools/winforms/controls/gridview/editors/using-custom-editors) and came up with this:
public class CustomCheckedListBox : BaseGridEditor
{
protected override RadElement CreateEditorElement()
{
return new CustomCheckedListBoxElement();
}
public override object Value
{
get
{
CustomCheckedListBoxElement element = this.EditorElement as CustomCheckedListBoxElement;
return element.CheckedDropDownElement.Value;
}
set
{
CustomCheckedListBoxElement element = this.EditorElement as CustomCheckedListBoxElement;
element.CheckedDropDownElement.Value = value;
}
}
public override void BeginEdit()
{
base.BeginEdit();
CustomCheckedListBoxElement element = this.EditorElement as CustomCheckedListBoxElement;
var statesData = new List<Dictionary>();
statesData.Add(new Dictionary { DictionaryKeyString = "AK", Description = "Alaska" });
statesData.Add(new Dictionary { DictionaryKeyString = "NJ", Description = "New Jersey" });
statesData.Add(new Dictionary { DictionaryKeyString = "AL", Description = "Alabama" });
statesData.Add(new Dictionary { DictionaryKeyString = "GA", Description = "Georgia" });
element.DataSource = statesData;
element.DropDownStyle = RadDropDownStyle.DropDownList;
element.ValueMember = "DictionaryKeyString";
element.DisplayMember = "Description";
}
public override bool EndEdit()
{
return base.EndEdit();
}
//public string? ValueMember { get; set; }
//public string? DisplayMember { get; set; }
//public object? DataSource { get; set; }
}
public class CustomCheckedListBoxElement : RadCheckedDropDownListElement
{
RadCheckedDropDownListElement dropDownListElement = new RadCheckedDropDownListElement();
public CustomCheckedListBoxElement()
{
}
public RadCheckedDropDownListElement CheckedDropDownElement
{
get => this.dropDownListElement;
}
protected override void CreateChildElements()
{
base.CreateChildElements();
}
}
What I get is a an empty dropdown in the cell with no data appearing. Ideally I'd like to instantiate the custom control and pass in the DataSource, ValueMember, etc. so I can reuse it elsewhere. The goal is to retrieve a list of selected states and display them like this when the cell is not in edit mode:
Alabama
New Jersey
Georgia
Any ideas on how to accomplish this?
Thanks
Carl