[RadGridView] Add Combo Box in Cell (GridViewTextBoxColumn)

1 Answer 467 Views
GridView
WEI TZE
Top achievements
Rank 2
Iron
Iron
WEI TZE asked on 19 Feb 2023, 06:50 AM

[Refer attached for sample project]

Question: How to add Combo Box in a RadGridView Cell?

Requirements:

  • The column is a GridViewTextBoxColumn, not GridViewComboBoxColumn.
  • Depending on the column type, the column will be populated dynamically with either Combo Box or Text Field.
  • Each combo box contains different items.

 

Sample below using DataGridView:


//DataGridView
            dataGridView1.Columns.Add("Item", "Item");
            dataGridView1.Columns.Add("Value", "Value");
            dataGridView1.Columns.Add("Type", "Type");
            dataGridView1.Columns.Add("Options", "Options");

            list = new List<string[]>();
            list.Add(new string[] { "Result", "DropDown", "Pass,Failed" });
            list.Add(new string[] { "UserId", "Text", "" });
            index = 0;
            foreach (string[] s in list)
            {
                dataGridView1.Rows.Add(s[0], "", s[1], s[2]);
                switch (s[1])
                {
                    case "DropDown":
                        DataGridViewComboBoxCell cmb = new DataGridViewComboBoxCell();
                        var selection = s[2].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        cmb.DataSource = selection;
                        this.dataGridView1.Rows[index].Cells[1] = cmb;
                        break;

                    case "Text":
                        this.dataGridView1.Rows[index].Cells[1].Value = "Text Field";
                        break;
                }
                index++;
            }

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 Feb 2023, 05:11 AM

Hello, WEI TZE,

I would recommend you to have a look at the second example in the following KB article which demonstrates how to show a drop down as an editor in a text column:

https://docs.telerik.com/devtools/winforms/knowledge-base/display-text-for-invalid-values-in-grid-combobox-column 

In the EditorRequired event you can either replace the editor or leave the default one according to the currently edited cell.

Feel free to modify and further extend the demonstrated approach in order to achieve the exact custom requirement you have.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
WEI TZE
Top achievements
Rank 2
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or