Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
945
Binding a table to an UltraCombo
posted

 Hi:

I am binding a DataTable to an ultracombo. My combo dropdown style is DropDownList, AutoEdit = False, CauseValidation = false. The combo shows the right rows, selection works, everything works except typing a character that is not part of the combo list (e.g. my rows are temp1, and temp2 and I am typing "m"). OnValueChanged kicks in and I am getting the followiing exception:
System.ArgumentException occurred  Message="Object of type 'System.DBNull' cannot be converted to type 'System.Int32'."
  Source="mscorlib"
  StackTrace:
       at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
  InnerException:

What I want to do is to be able to type something that is not in the list and in  "Validated" add the row to my table, refresh the control and show it in the combo and keeping/showing the row as selected. The binding for the combo is done in the code not in the designer and looks like this:

               TemplateCombo.ValueMember = Model.ImportTemplateDataSource.Columns["import_template_key"].ColumnName;
                TemplateCombo.DisplayMember = Model.ImportTemplateDataSource.Columns["description"].ColumnName;

ImportTemplateDataSource is defined as a DataTable property that set/gets a  table. 

 So any typing in the combo outside a match gets me the exception ablove. I beleive it has to do with the entry not having a key (PrimaryKey) yet or something like that. Is this due to the binding to the table or is some setting that I don't ahve right? 

Thanks, 

Mihail

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi Mihail,

    You cannot type into the Combo in DropDownList style. Although, I have never seen this raise an exception. My guess is that the exception is either a FirstChanceException that you are only seeing because you have the IDE set to break on all run-time exceptions, or else this exception is occurring somewhere in your code and not the UltraCombo. The third alternative is that this is a bug that is occurred because of the specific combination of settings you are using on the Combo. 

    In any case, if you want the users to be able to type into the combo, you have to use DropDown style, not DropDownList. 

    Regarding the auto-sizing, check out the DropDownWidth property on the control. The help describes several options you can use for this property that will give you different behavior. 

Reply Children