Hi All,
I am using an UltraComboEditor. I am binding it to a datatable. I tried to set the selected item of the combobox programmatically based on a value stored in the database before showing the combo box. But i am unable to see the selected item. I tried using SelectedITem,SelectedText,Value and Text property of the combo box, but couldn't make it work.
Am i missing something here?
Could any one please help me on this?
Thanks in Advance,
Hi Manikandan,
Setting the Value on the ComboEditor should work. Are you setting it before or after you bind the control? You should be binding first and setting the Value after.
Mike,
I think i am missing some thing here. Following is my code snippet.
comboBox.DataSource = itemsTable; // itemsTable is a data table with two columns "Caption" and "Values" and some n number of rows
comboBox.DataSource = itemsTable;
comboBox.ValueMember = "Values";
comboBox.Value = dc.DataValue; // dc.DataValue is the value to be selected. And i confirmed it that it has the correct value.
Manikandan
Oh, that makes sense. Without a contained, the Combo has no BindingContext. Without a BindingContext, it can't bind. Therefore, no data on the list, so that's why it didn't accept the Value you assigned.
Another solution would be to set the combo's BindingContext to a new BindingContext or ot the form's BindingContext.
Hi Mike,
Yes i was sure that the value to be selected was already there in the valuelist of the combobox. I was setting the value immediately after creating an instance of the combobox. I am creating an combo box object dynamically and then setting the datasource and the value to be selected. It wasn't working. However when i set the
comboBox.Value = dc.DataValue
after adding the combo box to a container, it is working fine.Anyways it is working now.
But i am not aware of the reason why combo editor has to be added to a container before setting a value.I am using TableLayoutPanel as my container.
Any Help on this?
Thanks in Advance.
Is that a typo or are you setting the DataSource twice?
Are you absolutely sure that dc.DataValue exists in the Values column? Is the the same value, same data type?
What event is this code in?