Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This line:</p> <pre><code>selectionBox.Items.Add(m.mName); </code></pre> <p>Is merely ading the name of the <code>module</code> to <code>selectionBox</code>, which would explain why you were having problems trying to cast a <code>string</code> to a <code>module</code>. What you need to look into is using databinding. Add this code in place of the <code>foreach (object o in module)</code> loop:</p> <pre><code>selectionBox.DataSource = module; selectionBox.DisplayMember = "mName"; </code></pre> <p>And in the index changed event you can retrieve the selected item like this:</p> <pre><code>modules m = (modules)selectionBox.SelectedItem; </code></pre> <p>Further, if you do retrieve the selected item in this way you can do away with the <code>for</code> loop you currently have in the index changed event handler.</p> <p><strong>Edit:</strong></p> <p>Currently you are adding the names of each <code>module</code> to the <code>selectionBox</code>. However, when you go to retrieve the selected item, you are getting an error as you are attempting to cast the name of the object to the actual object.</p> <p>So using my solution:</p> <pre><code>selectionBox.DataSource = module; </code></pre> <p>Assigns the list of objects you create to be the <code>DataSource</code> (i.e., where it gets its data from) of <code>selectionBox</code>, and</p> <pre><code>selectionBox.DisplayMember = "mName"; </code></pre> <p>Indicates which property of the object should be used as the display text. In this case I have <code>mName</code> as this was the property you were previously adding to <code>selectionBox</code>.</p>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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