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

SelectedValue Problem (resolved)

3 Answers 694 Views
MultiColumn ComboBox
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 2
Muhammad asked on 10 Mar 2014, 07:20 PM
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.

Thanks
Muhammad Waseem



3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 13 Mar 2014, 10:59 AM
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)
{
    base.OnLoad(e);
 
    this.radMultiColumnComboBox1 = new RadMultiColumnComboBox();
    this.Size = new System.Drawing.Size(300, 20);
    this.Controls.Add(this.radMultiColumnComboBox1);
 
    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.

Regards,
Stefan
Telerik
 

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

 
0
JeffSM
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 20 Nov 2019, 07:33 PM

I'm facing the same problema, from a DataTable datasource with field int,

when I set radMultiColumnComboBox1.SelectedValue = 3;

it remains radMultiColumnComboBox1.SelectedValue equals null!

what to do?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Nov 2019, 01:54 PM

Hello, Jeff,

Following the provided information, I was unable to reproduce the issue you are facing. Please refer to the below screenshot illustrating the behavior on my end with the specified version. I have attached my sample project. Could you please specify the exact steps how to reproduce the problem? Thank you in advance. 

I am looking forward to your reply.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Justine
Top achievements
Rank 1
commented on 21 Mar 2023, 12:45 PM

I have a C# winforms application using RadMultiColumComboBox (with data populating from another table in SQL Server) and while saving the selected record, the selectedvalue is not getting assigned and when we retrieve the saved record from database, the selectedvalue eveen after assigning multiple times will be null always and the selectedindex also will be -1 always. Please help me to overcome these issues.

this.rmcBrand.SelectedValue = Convert.ToInt32(fkBrand); This code is used to assign also, not working and the selected value is always null.

Below is the method used to assign the saved value from database to the control while loading the saved records.

public static string SetValueMultiColumnCombo(Telerik.WinControls.UI.RadMultiColumnComboBox control, string columnName, string columnValue)

{

DataRow[] drselectedItem = dtTemp.Select($"{columnName } = {columnValue}");
                        if (drselectedItem != null && drselectedItem.Length > 0)
                        {
                            int selectedIndex = dtTemp.Rows.IndexOf(drselectedItem[0]);
                            control.SelectedIndex = selectedIndex; //Getting error from here as selectedindex value is -1 always.
                        }

}

Dess | Tech Support Engineer, Principal
Telerik team
commented on 21 Mar 2023, 01:18 PM

Hi, Justine,

Your question has already been answered in the other thread you have opened on the same topic. Please, see our answer there for more information and use it for further communication on this topic.
We kindly ask you to use just one thread for a specific problem to contact us. Posting the same questions numerous times slows down our response time because we will need to review and address two or more tickets instead of one. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.

Thank you for your understanding.


Tags
MultiColumn ComboBox
Asked by
Muhammad
Top achievements
Rank 2
Answers by
Stefan
Telerik team
JeffSM
Top achievements
Rank 2
Iron
Veteran
Iron
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or