Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I resolve this casting error?
    primarykey
    data
    text
    <p>With the help of @competent_tech I have been able to get my comboboxitems to be selected via a button click and parsed through some VB code to get a document displayed. </p> <p>Everything seemed to be working fine, until I decided to bind the combobox to an XML file using the following code:</p> <pre><code>&lt;ComboBox Name="ComboBox1" ItemsSource="{Binding Source={StaticResource vehicleID}, XPath=//manualtype/ipck/vin}" IsReadOnly="True"&gt;&lt;/ComboBox&gt; </code></pre> <p>This is the code I'm using on the button.click event:</p> <pre><code>Try Dim sFileName As String If ComboBox1.SelectedValue IsNot Nothing Then sFileName = DirectCast(ComboBox1.SelectedValue, ComboBoxItem).Content.ToString() Dim theDocument As New System.Windows.Xps.Packaging.XpsDocument(System.IO.Path.Combine("C:\EMR", sFileName &amp; "ipck.xps"), System.IO.FileAccess.Read) DocumentViewer1.Document = theDocument.GetFixedDocumentSequence() End If Catch ex As Exception MessageBox.Show("ERROR: " &amp; ex.Message) End Try </code></pre> <p>The combobox is working fine - displaying the values from the XML file, however, I am now getting an error message whenever I select an item and click the button. The error message states: "UNABLE TO CAST OBJECT OF TYPE 'SYSTEM.STRING' TO TYPE 'SYSTEM.WINDOWS.CONTROLS.COMBOBOXITEM'.</p> <p>Please help me resolve this problem, as I'd like to be able to update the comboboxitem list via the XML file rather than having to recode the software each time I want to update the list. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload