//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
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.
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?
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
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.
}
}
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.