TargetInvocationException using MicroFour.StrataFrame.UI.Windows.Forms.DevEx.ComboBoxEdit


Author
Message
Lukasz Kustusz
Lukasz Kustusz
StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)
Group: Forum Members
Posts: 29, Visits: 125
Hello

I have a MicroFour.StrataFrame.UI.Windows.Forms.DevEx.ComboBoxEdit on a SF DevEx MaintenanceForm, which is bound to a BO1. The Combo box has BO1 in BusinessObject property and I filled BindingField to one of the fields in BO1 (btw, how come there's no dropdown on the BindingField on DevEx controls from the Inherited UI wrapper, like there is for native Strataframe controls?) I also fill some values in Edit Values item of the context menu for the control. They are stored in Items collection.

At runtime, whenever I choose one of the items from the list I get this:


TargetInvocationException
  Property accessor 'SelectedValue' on object 'MicroFour.StrataFrame.UI.Windows.Forms.DevEx.ComboBoxEdit' threw the following exception:'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'
ArgumentOutOfRangeException
  Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source     : System

Stack Trace: 
   at System.Collections.ArrayList.get_Item(Int32 index)
   at MicroFour.StrataFrame.UI.Windows.Forms.ComboBoxItemCollection.get_Item(Int32 Index)
   at MicroFour.StrataFrame.UI.Windows.Forms.DevEx.ComboBoxEdit.get_SelectedValue()
   at System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component)
   at System.Windows.Forms.Binding.GetPropValue()
   at System.Windows.Forms.Binding.PullData(Boolean reformat, Boolean force)
   at System.Windows.Forms.Binding.Target_PropertyChanged(Object sender, EventArgs e)
   at DevExpress.XtraEditors.Repository.RepositoryItemComboBox.RaiseSelectedValueChanged(EventArgs e)
   at DevExpress.XtraEditors.ComboBoxEdit.UpdatePopupEditValueIndex(Int32 prevIndex)
   at DevExpress.XtraEditors.ComboBoxEdit.set_EditValue(Object value)
   at DevExpress.XtraEditors.PopupBaseEdit.AcceptPopupValue(Object val)
   at DevExpress.XtraEditors.PopupBaseEdit.UpdateEditValueOnClose(PopupCloseMode closeMode, Boolean acceptValue, Object newValue, Object oldValue)
   at DevExpress.XtraEditors.PopupBaseEdit.DoClosePopup(PopupCloseMode closeMode)
   at DevExpress.XtraEditors.PopupBaseEdit.ClosePopup(PopupCloseMode closeMode)
   at DevExpress.XtraEditors.PopupBaseEdit.ClosePopup()
   at DevExpress.XtraEditors.Popup.PopupListBox.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)



And the combobox gets red x icon on the left saying "invalid item". 
Lukasz Kustusz
Lukasz Kustusz
StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)
Group: Forum Members
Posts: 29, Visits: 125
I have some new developments in this issue. I tried to replace the DevEx ComboBox from the SF wrapper with a native SF ComboBox. With this one there is another error whenever I choose an item from the list.:

InvalidCastException
  Conversion from type 'DBNull' to type 'String' is not valid.

Source     : Microsoft.VisualBasic

Stack Trace: 
   at Microsoft.VisualBasic.CompilerServices.Conversions.ToString(Object Value)
   at ChemineeLining.boEventLog.FieldDescriptor.SetValue(Object component, Object value) in C:\Development\CL_BO_NotesChrono\CL_BO_NotesChrono\CL_BOs\boEventLog.Designer.vb:line 1338
   at System.Windows.Forms.BindToObject.SetValue(Object value)
   at System.Windows.Forms.Binding.PullData(Boolean reformat, Boolean force)
   at System.Windows.Forms.Binding.Target_PropertyChanged(Object sender, EventArgs e)
   at System.Windows.Forms.ListControl.OnSelectedValueChanged(EventArgs e)
   at System.Windows.Forms.ComboBox.OnSelectedValueChanged(EventArgs e)
   at System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)
   at System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
   at System.Windows.Forms.ComboBox.WndProc(Message& m)
   at MicroFour.StrataFrame.UI.Windows.Forms.ComboBox.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)




I tried populating the elements at design time , using Edit Items from context menu, or at runtime using following code:



 Me.cboFait.Items.Add("Fait")
 Me.cboFait.Items.Add("A faire")
 Me.cboFait.Items.Add("Annule")


The Items are there, but as soon as I try to choose one, either by clicking on it, or from the code by setting SelectedItem property, I get the above error.

If I try to type the value instead, without opening the list, it doesn't accept my value - the business rule is triggered saying that this is a required field and cannot be empty, even though the typed value is there. If I replace the combobox with textbox and type the value, then it's accepted fine. I need this to be a ComboBox though. One that's binded to my BO yet providing default string values to choose from.  How can I make it work?
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Likely the problem is that BindingProperty isn't setup correctly. This is the property of the combo that is bound to the data. In your second example you are adding strings, so there is no SelectedValue property available (or it is always DBNullValue).  You'd need to use SelectedText instead.  Likely this is also the issue with the first example. It could be that you need to use a different property of the DevEx combo to get the correct value, based on how you are filling it. 
Lukasz Kustusz
Lukasz Kustusz
StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)StrataFrame Beginner (49 reputation)
Group: Forum Members
Posts: 29, Visits: 125
Greg,

Thank you for your help. You pointed me in the right direction. I tried to change the Binding property to SelectedText, but it didn't work.  I then tried to bind to a few other properties and it finally worked with SelectedItem. It works with either DevEx and native version of ComboBox.


Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Excellent. I thought that might be the problem and often you just have to experiment a bit to figure out the right one, based on how you're loading the Combo.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search