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
Hm, that's odd. Must be because the rows are getting destroyed and recreated and it's not refreshing. You might have to refresh the grid rows after you refresh the combo / dropdown rows.
Thanks Mike!
It doesn't affect the the dropdown width but it dipalys the key instead of the description until I drop down the list to make a selection. Don't know why yet.
Oh, by the way... resetting the data source on the UltraDropDown it probably overkill. You can probably acheive the same thing by calling ultraCombo.Rows.Refresh(ReloadData). And that should not affect the dropdown width.
I beleive the third case (combinations of combo settings) might casue this problem, although I wasn't able to figure it out. The style for the combo was/is DropDow, my mistake. I got it working now. I will see how can I resize the DropDownWidth for the combo when I am deleting items.
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.