﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » I am getting a "Specified cast is not valid." when I try to default a value</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 02:35:24 GMT</lastBuildDate><ttl>20</ttl><item><title>I am getting a "Specified cast is not valid." when I try to default a value</title><link>http://forum.strataframe.net/FindPost19801.aspx</link><description>Hi all.&lt;/P&gt;&lt;P&gt;This should be something simple, but I don't know how to fix it.&lt;/P&gt;&lt;P&gt;here is the code:&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;private&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;FONT size=2&gt; cboitem_fk_SelectionChangeCommitted(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;object&lt;/FONT&gt;&lt;FONT size=2&gt; sender, &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;EventArgs&lt;/FONT&gt;&lt;FONT size=2&gt; e)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;if&lt;/FONT&gt;&lt;FONT size=2&gt; (boDefaultPrice.SeekToPrimaryKey( &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Convert&lt;/FONT&gt;&lt;FONT size=2&gt;.ToInt32(cboitem_fk.SelectedValue.ToString())))&lt;/P&gt;&lt;P&gt;boProposalCosts.item_amt = boDefaultPrice.item_amt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;the funny thing is that it displays the item price in the text box&amp;nbsp; and then the error is thrown and my combo box goes blank.&lt;/P&gt;&lt;P&gt;Here is the stack trace:&lt;/P&gt;&lt;P&gt;InvalidCastException&lt;BR&gt;&amp;nbsp; Specified cast is not valid.&lt;/P&gt;&lt;P&gt;Source&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Trinity&lt;/P&gt;&lt;P&gt;Stack Trace: &lt;BR&gt;&amp;nbsp;&amp;nbsp; at Trinity.BusinessObjects.boProposalCosts.Field_item_fk_Descriptor.SetValue(Object component, Object Value) in F:\Trinity_new\Trinity\BusinessObjects\boProposalCosts.Designer.cs:line 651&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.BindToObject.SetValue(Object value)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.Binding.PullData(Boolean reformat, Boolean force)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.Binding.Target_PropertyChanged(Object sender, EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.ListControl.OnSelectedValueChanged(EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.ComboBox.OnSelectedValueChanged(EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.ComboBox.WmReflectCommand(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.ComboBox.WndProc(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at MicroFour.StrataFrame.UI.Windows.Forms.ComboBox.WndProc(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.Control.ControlNative&amp;#119;indow.OnMessage(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.Control.ControlNative&amp;#119;indow.WndProc(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.Native&amp;#119;indow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)&lt;BR&gt;&lt;/P&gt;&lt;P&gt;What am I missing here? This should be sead simple.&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Mon, 29 Sep 2008 09:35:33 GMT</pubDate><dc:creator>Marcia G Akins</dc:creator></item><item><title>RE: I am getting a "Specified cast is not valid." when I try to default a value</title><link>http://forum.strataframe.net/FindPost19817.aspx</link><description>Glad you got it going.&amp;nbsp; :)</description><pubDate>Mon, 29 Sep 2008 09:35:33 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: I am getting a "Specified cast is not valid." when I try to default a value</title><link>http://forum.strataframe.net/FindPost19802.aspx</link><description>Well, now I am really surprised. All I did was add this line after setting the item_amt:&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;cboitem_fk.SelectedValue = boDefaultPrice.item_pk;&lt;/P&gt;&lt;P&gt;and the problem went away.&lt;/P&gt;&lt;P&gt;Sometimes I would rather be lucky than good :P&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Sun, 28 Sep 2008 12:46:21 GMT</pubDate><dc:creator>Marcia G Akins</dc:creator></item></channel></rss>