I have several combo boxes that are databound and populated from a list.
Both controls are populated from the same table and structure:
var status = new AgencyDetail().GetAgencyStatus(); foreach (var item in status) { StatusComboBox.Items.Add(item.Value, item.Label); } // Producer or CSR var prodType = new AgencyDetail().GetProducerType(); foreach (var item in prodType) { ProducerTypeIdCombo.Items.Add(item.Value, item.Label); }
this is how I currently bind its value:
StatusComboBox.DataBindings.Add("Value", Producer, "Status"); ProducerTypeIdCombo.DataBindings.Add("Value", Producer, "ProducerTypeId");
Everything looks correct in the UI they have the correct display and value, which is numeric.
When changing the StatusCombo in the UI it works as expected. When I change the ProducerType it always reverts back to the original bound value.
Both list have 3 or more items. I have manually change the value in the DB and it is displayed correctly in the UI.
I have several other comboboxes that behave the same but use a different table for the data.
I don't get why one works and the others don't. I have deleted/created and copied the control with no changes.
Help!!!
If changing the data type of the database column fixes the problem, the only logical conclusion is that the corresponding property in the entity framework implementation is of a type not compatible with integers. Search the entity framework implementation source code for the name of the database column in question, and take a look at each line of code in the search results; odds are you will see something in there that indicates a type disparity.
OK i have implemented the derived class and created a combobox at runtime.
I am getting the same results. the selected value reverts back to original on loss of focus.
On the new control i bound it to the new values:
//ProducerTypeIdCombo.DataBindings.Add("Value", Producer, "ProducerTypeId"); Combo1.DataBindings.Add("IntegerValue", Producer, "ProducerTypeId");
If i go back and change the column type in SQL to a nvarchar it will work as expected. But I need valid columns types.
Any ideas?
https://msdn.microsoft.com/en-us/library/vstudio/ms173149(v=vs.100).aspx
Example:
public class DerivedFromUltraComboEditor : UltraComboEditor { public string StringValue { get { object value = base.Value; return value == null ? string.Empty : value.ToString(); }
set { base.Value = value; } }
public int IntegerValue { get { object value = base.Value; if ( value is int ) return (int)value; else return 0; }
set { base.Value = value; } } }
thanks for the reply. Basically what i have determined is that somewhere along the way the bound value will only save back to a string column in the database. If the column type in the entity is anything other than string it will not allow me to change the selected value of the combo. I dont know if this is a bug or how i have the entity framework setup.
Do you have a link to a reference on how to create the derived class? a quick search was overwhelming.
I'm not exactly following your description of the interactions between integers and strings in this scenario, but yes, there is a way to bind to an Int32 property...what you would need to do is derive a class from UltraComboEditor, and add a new settable public property to this derived class, let's call it 'IntValue', of type Int32. That property's implementation would simply get/set the value of the UltraComboEditor's Value property, cast to an integer.