This is a migrated thread and some comments may be shown as answers.

Programaticly Adding Data to Multicolum Combox Box

3 Answers 714 Views
MultiColumn ComboBox
This is a migrated thread and some comments may be shown as answers.
Denis Cilliers
Top achievements
Rank 1
Denis Cilliers asked on 02 Oct 2012, 01:41 PM
Please can we have an example of adding a row to the Multi Column Combo Box, that does not use a Datasource

I wanted to have a column with a name and another with a checkbox.

it seems rather simple, but there is no example in the documentation that details a simple add items

I did manage to add records via a datatable, but this does not add to the existing columns in the control, but adds new columns
And does not set the value of the checkbox

Sub LoadData()
 
        Dim table1 As DataTable = New DataTable()
 
        table1.Columns.Add("ID")
        table1.Columns.Add("Name")
        table1.Columns.Add("Selected")
 
        table1.Rows.Add(1, "Ivan Petrov", True)
        table1.Rows.Add(2, "Stefan Muler", True)
        table1.Rows.Add(3, "Alexandro Ricco", False)
 
        cboTestCheckbox.DataSource = table1
        cboTestCheckbox.DisplayMember = "Name"
 
 
    End Sub

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 09 Oct 2012, 06:13 AM
Hi Denis,

Thank you for writing.

Attached you can find a sample project demonstrating how to setup and how to add rows in both bound and unbound RadMultiColumnComboBox.

I hope this helps.
  
Greetings,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Joem
Top achievements
Rank 2
answered on 12 Mar 2015, 02:48 AM
I thought that the problem I am encountering was due to the unbound RadMultiColumnComboBox.

I am using the RadMultiColumnComboBox just like the way the unbound RadMultiColumnComboBox was use in this sample.
The only difference of the solution is that the control was added to the form onruntime.

Instead of showing the value the display member has, it shows Telerik.WinControls.UI.GridViewDataRowInfo .
Also, I get a runtime error if I clicked on the dropdown grid. But no error if I used the arrow keys to select a record.

I made a test project with this scenario. The Form is blank at startup.

Does this mean that we cannot add controls on runtime?

Below is the code. 
private void Form1_Load(object sender, EventArgs e)
        {
            var comboBox = new RadMultiColumnComboBox();
            this.Controls.Add(comboBox);
            comboBox.EditorControl.ShowColumnHeaders = false;
            comboBox.DropDownStyle = RadDropDownStyle.DropDownList;
            comboBox.Font = new System.Drawing.Font("Verdana", 9F,
                System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            comboBox.EditorControl.ShowHeaderCellButtons = false;
            comboBox.EditorControl.ShowRowHeaderColumn = false;
            comboBox.EditorControl.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            comboBox.Size = new Size(500, 20);
 
            var source = SampleData();
 
            foreach (DataColumn dataColumn in source.Columns)
                comboBox.EditorControl.Columns.Add(dataColumn.ColumnName, dataColumn.ColumnName);
 
            foreach (DataRow dataRow in source.Rows)
                comboBox.EditorControl.Rows.Add(dataRow.ItemArray);
 
            if (comboBox.Columns.Contains("Value"))
            {
                comboBox.Columns["Value"].IsVisible = false;
                comboBox.DisplayMember = "Value";
                comboBox.ValueMember = "Value";
            }
             
 
        }
 
        DataTable SampleData()
        {
            var dt = new DataTable();
 
            dt.Columns.Add("Name");
            dt.Columns.Add("Description");
            dt.Columns.Add("Value");
 
            dt.Rows.Add(new object[] { "1", "Low", "1 - Low" });
            dt.Rows.Add(new object[] { "2", "Medium", "2 - Medium" });
            dt.Rows.Add(new object[] { "3", "High", "3 - High" });
 
            return dt;
        }





0
Stefan
Telerik team
answered on 12 Mar 2015, 07:22 AM
Hi Joem,

When adding columns, you would also need to specify their FieldName, as this is how the control is currently looking them up. Here is what you need to change in your code:
foreach (DataColumn dataColumn in source.Columns)
              comboBox.EditorControl.Columns.Add(dataColumn.ColumnName, dataColumn.ColumnName, dataColumn.ColumnName);

just add the third parameter as well.

I hope this helps.

Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
MultiColumn ComboBox
Asked by
Denis Cilliers
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Joem
Top achievements
Rank 2
Share this question
or