Programaticly Adding Data to Multicolum Combox Box

4 posts, 0 answers
  1. Denis Cilliers
    Denis Cilliers avatar
    62 posts
    Member since:
    Jan 2004

    Posted 02 Oct 2012 Link to this post

    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

  2. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 09 Oct 2012 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Joem
    Joem avatar
    11 posts
    Member since:
    Oct 2012

    Posted 11 Mar 2015 in reply to Stefan Link to this post

    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;
            }





  5. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 12 Mar 2015 Link to this post

    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.

     
Back to Top