StrataFrame Forum

I am getting a "Specified cast is not valid." when I try to default a value

http://forum.strataframe.net/Topic19801.aspx

By Marcia G Akins - 9/28/2008

Hi all.

This should be something simple, but I don't know how to fix it.

here is the code:

private void cboitem_fk_SelectionChangeCommitted(object sender, EventArgs e)

{

if (boDefaultPrice.SeekToPrimaryKey( Convert.ToInt32(cboitem_fk.SelectedValue.ToString())))

boProposalCosts.item_amt = boDefaultPrice.item_amt;

}

the funny thing is that it displays the item price in the text box  and then the error is thrown and my combo box goes blank.

Here is the stack trace:

InvalidCastException
  Specified cast is not valid.

Source     : Trinity

Stack Trace:
   at Trinity.BusinessObjects.boProposalCosts.Field_item_fk_Descriptor.SetValue(Object component, Object Value) in F:\Trinity_new\Trinity\BusinessObjects\boProposalCosts.Designer.cs:line 651
   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)

What am I missing here? This should be sead simple.

By Marcia G Akins - 9/28/2008

Well, now I am really surprised. All I did was add this line after setting the item_amt:

cboitem_fk.SelectedValue = boDefaultPrice.item_pk;

and the problem went away.

Sometimes I would rather be lucky than good Tongue

By Trent L. Taylor - 9/29/2008

Glad you got it going.  Smile