Note that there are some explanatory texts on larger screens.

plurals
  1. POHow To Link ComboBoxItem to File
    primarykey
    data
    text
    <p>This question is a follow-up to one I asked and got answered here: <a href="https://stackoverflow.com/questions/8636128/how-to-display-xps-document-using-a-selected-combobox-item">How to display XPS document using a selected combobox item</a></p> <p>I've created a WPF app using VB 2010. I set the comboboxitems via the XAML. However, I can't seem to figure out how to set the value of each item to a file path.</p> <p>The objective is for a user to be able to select an item from a drop-down list, then that selection opens an XPS file in the DocumentViewer. The code below was provided to me by COMPETENT_TECH (thanks) to read and display the value of the selected comboboxitem in the DocumentViewer.</p> <p>The path to the files I want opened is C:\folder\file.xps</p> <pre><code>Private Sub Button4_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button4.Click Try Dim sFileName As String sFileName = DirectCast(ComboBox1.SelectedValue, String) If Not String.IsNullOrEmpty(sFileName) Then Dim theDocument As New System.Windows.Xps.Packaging.XpsDocument(sFileName, System.IO.FileAccess.Read) DocumentViewer1.Document = theDocument.GetFixedDocumentSequence() End If Catch ex As Exception MessageBox.Show("ERROR: " &amp; ex.Message) End Try End Sub </code></pre> <p>Thanks in advance for your assistance.</p> <p><strong>Update</strong></p> <p>Here's the XAML I'm using: </p> <pre><code>&lt;ComboBox Width="Auto" IsReadOnly="True" IsEditable="True" Name="ComboBox1" Height="Auto" Margin="0" Padding="1" Grid.Column="2"&gt; &lt;ComboBoxItem&gt;123456&lt;/ComboBoxItem&gt; &lt;ComboBoxItem&gt;123457&lt;/ComboBoxItem&gt; &lt;ComboBoxItem&gt;123458&lt;/ComboBoxItem&gt; &lt;/ComboBox&gt; </code></pre>
    singulars
    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.
 

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