I am trying to create a GridViewCheckedDropDownListColumn. I have some of it working.
It is creating the column and the drop-down is displaying as it should. However, the main cell does not show the checked items after the drop-down is no longer displayed. Nor does it remember which items had previously been checked when the drop-down is displayed a second time.
I wasn't able to attach my project, so here is the important code:
public class Foo{ public int Id { get; set; } public string Value { get; set; } public bool IsSelected { get; set; }}public class Boo : Foo{ public List<Foo> Foos { get; set; } public Boo() { this.Foos = new List<Foo>(); }}
public class RadCheckedDropDownListEditorElement : RadCheckedDropDownListElement{ ...}public class RadCheckedDropDownListEditor : BaseGridEditor{ public string ValueMember { get; set; } public string DisplayMember { get; set; } public string CheckedMember { get; set; } public override object Value { get { var listEditorElement = (RadCheckedDropDownListElement) this.EditorElement; return listEditorElement.DataSource; } set { var listEditorElement = (RadCheckedDropDownListElement) this.EditorElement; listEditorElement.ValueMember = this.ValueMember; listEditorElement.DisplayMember = this.DisplayMember; listEditorElement.CheckedMember = this.CheckedMember; listEditorElement.DataSource = value; } } [AttributeProvider(typeof(IListSource))] [RadDescription("DataSource", typeof(RadListElement))] [Category("Data")] [RadDefaultValue("DataSource", typeof(RadListElement))] public object DataSource { get { var listEditorElement = (RadCheckedDropDownListElement)this.EditorElement; return listEditorElement.DataSource; } set { var listEditorElement = (RadCheckedDropDownListElement)this.EditorElement; listEditorElement.DataSource = value; } } protected override RadElement CreateEditorElement() { return new RadCheckedDropDownListEditorElement(); }}public class GridViewCheckedDropDownListColumn : GridViewComboBoxColumn{ private RadCheckedDropDownListEditor _editor; private string _checkedMember; [Browsable(true)] [Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] [Category("Data")] [DefaultValue(null)] [Description("Gets or sets a string that specifies the property or database column from which to get values that correspond to the items in the RadDropDownListEditor.")] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] public string CheckedMember { get { return this._checkedMember; } set { if (this._checkedMember == value) return; this._checkedMember = value; this.DispatchEvent(KnownEvents.ColumnDataSourceInitializing, GridEventType.UI, GridEventDispatchMode.Send, (object)null, (object[])null); } } public GridViewCheckedDropDownListColumn() { } public GridViewCheckedDropDownListColumn(string fieldName) : base(fieldName) { } public GridViewCheckedDropDownListColumn(string uniqueName, string fieldName) : base(uniqueName, fieldName) { } public override Type GetDefaultEditorType() { return typeof(RadCheckedDropDownListEditor); } public override IInputEditor GetDefaultEditor() { return new RadCheckedDropDownListEditor(); } public override void InitializeEditor(IInputEditor editor) { var dropDownListEditor = (RadCheckedDropDownListEditor) editor; if (dropDownListEditor == null) return; dropDownListEditor.ValueMember = this.ValueMember; dropDownListEditor.DisplayMember = this.DisplayMember; dropDownListEditor.CheckedMember = this.CheckedMember; dropDownListEditor.DataSource = this.DataSource; } public virtual void RadGridView_EditorRequired(object sender, EditorRequiredEventArgs e) { if (e.EditorType == typeof(RadCheckedDropDownListEditor)) { e.Editor = this._editor ?? (this._editor = new RadCheckedDropDownListEditor()); } }}
public partial class Form1 : Form{ private List<Boo> _boos; public Form1() { this.InitializeComponent(); this.InitializeList(); this.InitializeColumns(); this.radGridView.DataSource = this._boos; } private void InitializeList() { this._boos = new List<Boo>(); for (int i = 0; i < 10; i++) { Boo b = new Boo { Id = i, Value = $"Boo-{i}" }; for (int j = 0; j < 10; j++) { Foo f = new Foo { Id = j, Value = $"Foo-{i}.{j}" }; b.Foos.Add(f); } this._boos.Add(b); } } private void InitializeColumns() { var c1 = new GridViewTextBoxColumn(nameof(Boo.Id)); var c2 = new GridViewTextBoxColumn(nameof(Boo.Value)); var c3 = new GridViewCheckedDropDownListColumn(nameof(Boo.Foos)) { ValueMember = nameof(Foo.Id), DisplayMember = nameof(Foo.Value), CheckedMember = nameof(Foo.IsSelected), Width = 500 }; this.radGridView.Columns.Add(c1); this.radGridView.Columns.Add(c2); this.radGridView.Columns.Add(c3); this.radGridView.EditorRequired += c3.RadGridView_EditorRequired; }}