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