I've got an UltraCombo thats filled with Product Objects, these objects have a Customer object as a property (the foreign key). 2 of these products have their Name property set with an identical value.
The value's look like this:
Customer Product name
DNM1 HRT
DNM2 HRT
Now i try to set the selected value like this:
cboProduct.Value = product;
Product here is the DNM2/HRT object. Now when i debug this it appears to work fine. cboProduct.Value contains the right value. However when i do the following:
(Product)cboProduct.SelectedRow.ListObject;
It returns DNM1/HRT which is incorrect. The weird thing is when i actually use the ComboBox and select the right value by hand then it returns the correct value. I've also tried to loop through all the rows and set the Selected property to true but that gives the same result.
Instead of retreiving the ListObject value i tried to access the Value like this:
(Product)cboProduct.Value;
This works fine when setting the value in the code. However when i then set it by hand it gives back the string of the name instead of the Product Object.
I do override the ToString() method of the Product Object but removing that didn't change a thing. Same thing goes for the DisplayMember property of the Combobox. Its set to Name now but removing that didn't help either.
In short there are 2 things that i do not understand at all:
- Why does ListObject give me back the wrong value even though i selected the right one, what so different about selecting the value by hand?
- Why does the Value ever change to a string when the ComboBox holds Product Objects?
What version of the controls are you using?
Does setting the Value to anything update the SelectedRow? Does this work for any value? If this works for other values and not for this one case where the text is the same, then it sounds like a bug to me. But I'm not sure that the SelectedRow is updated at all when you set the Value. It might not be updated until the list is dropped down. After all, there is really no reason for the SelectedRow to be updated unless the user can see the list.
If I am wrong and this works for other values, then it's probably a bug, in which case we will need a small sample project demonstrating this so we can check it out and get it fixed.
Either way, you could probably get around it by casting the UltraCombo into an IValueList. Then you can use the GetTextMethod to find the row associated with the Value you want and get the correct row.
Thanks for your reply, i managed to fix it myself but i will stil reply incase someone else can use it.
I'm using version 2058. It correctly sets the value unless the sames are identical. I have no ValueMember set but i'm guessing that it picks the name by default because thats the first value. SelectedRow did got updated with the wrong ListObject directly after setting the value.
However when creating the demo project somehow the value of the UltraCombo stayed null after setting the value. I have no idea why this did work in the demo project and did work in my own project. However it caused me to try to set the value like this:
cboProduct.Value = product.Id;
With the valuemember of the combobox being set to Id. This way it does set the correct value.
My best guess is that the ComboBox sets the name property as valuemember and tries to set the value based on that.