SelectedValue Problem (resolved)

2 posts, 0 answers
  1. Muhammad
    Muhammad avatar
    2 posts
    Member since:
    Apr 2013

    Posted 10 Mar 2014 Link to this post

    I was facing problem in setting the SelectedValue property of MutiColumnComboBox. Even after spending few hours in search and trying doing different things I couldn't figure out the problem. Just before submitting the support ticket I figured out that you need to set the property using the Object not the value. Here is the example.

    //This doesn't work
    MultiColumnComboBox.SelectedValue = 1;
    //This is the correct way of seeting the value
    MultiColumnComboBox.SelectedValue = "1";
    //Another way
    MultiColumnComboBox.SelectedValue = Convert.ToInt32(intValue).ToString();

    Posting the as thread so others can save time.

    Muhammad Waseem

  2. Stefan
    Stefan avatar
    2906 posts

    Posted 13 Mar 2014 Link to this post

    Hello Muhammad,

    Thank you for writing.

    When you bind MutiColumnComboBox you specify DisplayMember and ValueMember - the first determines which field it should display, the second which field the control should use for its value. So, to change the SelectedValue, you need to set it to a valid value from the ValueMember field. Here is a small example:
    protected override void OnLoad(EventArgs e)
        this.radMultiColumnComboBox1 = new RadMultiColumnComboBox();
        this.Size = new System.Drawing.Size(300, 20);
        Random random = new Random();
        DataTable dataTable = new DataTable();
        dataTable.Columns.Add("ID", typeof(int));
        dataTable.Columns.Add("Name", typeof(string));
        dataTable.Columns.Add("Bool", typeof(bool));
        dataTable.Columns.Add("DateColumn", typeof(DateTime));
        for (int i = 0; i < 20; i++)
            dataTable.Rows.Add(i, "Row " + i, random.Next(10) > 5 ? true : false, DateTime.Now.AddDays(i));
        this.radMultiColumnComboBox1.DataSource = dataTable;
        this.radMultiColumnComboBox1.DisplayMember = "Name";
        this.radMultiColumnComboBox1.ValueMember = "ID";
    private void radButton1_Click(object sender, EventArgs e)
        radMultiColumnComboBox1.SelectedValue = 3;

    We are setting the SelectedValue to 3, not "3" as the ValueMember field is of type int.

    I hope this clear things up.


    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

Back to Top