I'm trying to swap out the datasource on a ComboBoxColumn depending on other data bound to the row. Below is a simple example to reproduce the problem. (In my actual project we are not using simple strings for the options)
In this example the second row's combo box should have a 3rd option not shown by the first row.
If I let the grid automatically generate columns instead of adding it manually it seems to work correctly. What am I doing wrong?
Relevant code behind for the form:
In this example the second row's combo box should have a 3rd option not shown by the first row.
If I let the grid automatically generate columns instead of adding it manually it seems to work correctly. What am I doing wrong?
public class SimpleObject { public string Option { get; set; } public bool ShowOtherOptions { get; set; } public SimpleObject (string option) { Option = option; } }Relevant code behind for the form:
private List<String> options = new List<String>(){"First", "Second"};private List<String> specialoptions = new List<String>(){ "First", "Second", "Third"};public SimpleSample () { List<SimpleObject> myList = new List<SimpleObject> (); myList.Add (new SimpleObject ("First")); myList.Add (new SimpleObject ("Second") {ShowOtherOptions = true}); InitializeComponent (); this.radGridView1.AutoGenerateColumns = false; AddComboColoumn (); radGridView1.DataSource = myList; radGridView1.EditorRequired += radGridView1_EditorRequired; }private void AddComboColoumn(){ GridViewComboBoxColumn comboColumn = new GridViewComboBoxColumn("ComboBox column"); comboColumn.Width = 150; comboColumn.FieldName = "Option"; comboColumn.DataSource = options; radGridView1.Columns.Add(comboColumn);}private void radGridView1_EditorRequired (object sender, Telerik.WinControls.UI.EditorRequiredEventArgs e) { if (radGridView1.CurrentColumn.Name == "Option") { var data = (((Telerik.WinControls.UI.GridViewEditManager) (sender)).GridViewElement.CurrentRow).DataBoundItem as SimpleObject; RadDropDownListEditor dropdownEditor = new RadDropDownListEditor (); if (data.ShowOtherOptions) { ((RadDropDownListEditorElement) (dropdownEditor.EditorElement)).DataSource = specialoptions; } else { ((RadDropDownListEditorElement) (dropdownEditor.EditorElement)).DataSource = options; } dropdownEditor.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList; e.Editor = dropdownEditor; } }
