Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that you are using the wrong control for the job. You need a control that can display multiple columns of data for each item in a list. The <code>ListBox</code> control is not well-suited for that, since it is designed for just showing a single column. </p> <p>Assuming this is a WinForm project, and not WPF, I would recommend using either a <code>DataGridView</code> control, or a <code>ListView</code> control. Either of those controls can show multiple columns, although, the <code>ListView</code> control only shows multiple columns with its <code>View</code> property is set to <code>Details</code>. Since I'm partial to the <code>ListView</code> control, myself, I'll give you an example using that one :)</p> <p>First, add a <code>ListView</code> control to your form. Then, set the <code>View</code> property of the control, in the designer, to <code>Details</code>. Then click the button to edit the <code>Columns</code> property of the control. Add two columns. Then, use code like this to populate the list:</p> <pre><code>Dim item As ListViewItem = ListView1.Items.Add("Premium") item.SubItems.Add("400") item = ListView1.Items.Add("") item.SubItems.Add("500") item = ListView1.Items.Add("") item.SubItems.Add("600") item = ListView1.Items.Add("") item.SubItems.Add("700") item = ListView1.Items.Add("Cover") item.SubItems.Add("TPO") item = ListView1.Items.Add("") item.SubItems.Add("TPFT") </code></pre> <p>If, as seems to be the case, the text for the first column is stored in a combo box, then the text for the second column are stored in a comma-delimited text box, then you could do something like this:</p> <pre><code>For Each cbo As ComboBox In MyComboBoxes Dim first As Boolean = True For Each value As String In GetTextBoxForComboBox(cbo).Text.Split(",") Dim item As ListViewItem = Nothing If first Then item = ListView1.Items.Add(cbo.Text) Else item = ListView1.Items.Add("") End If item.SubItems.Add(value) first = False Next Next </code></pre> <p>Of course, rather than having a method like <code>GetTextBoxForComboBox</code>, it would be better to have have a class that stores the pairing of controls, like this:</p> <pre><code>Private Class ControlPair Public Property Cbo As ComboBox Public Property Txt As TextBox End Class </code></pre> <p>Then, you could just loop through them like this:</p> <pre><code>For Each pair As ControlPair In MyPairs ' ... For Each value As String In pair.Txt.Text.Split(",") ' ... ListView1.Items.Add(pair.Cbo.Text) ' ... Next Next </code></pre> <p><code>For Each</code> is a convenient syntax for iterating through all of the items in an <code>IEnumerable</code> object (basically any list such as an <code>Array</code> or a <code>List(Of T)</code>). So, in this case, the <code>MyPairs</code> would need to be a list of <code>ControlPair</code> objects, for instance:</p> <pre><code>Dim MyPairs As New List(Of ControlPair)() Dim pair1 As New ControlPair() pair1.Cbo = ComboBox1 pair1.Txt = TextBox1 MyPairs.Add(pair1) Dim pair2 As New ControlPair() pair2.Cbo = ComboBox2 pair2.Txt = TextBox2 MyPairs.Add(pair2) </code></pre> <p>Or, if you don't want to make your own class, you could just use <code>Tuple(Of ComboBox, TextBox)</code>.</p> <p>Actually, after seeing your screenshots, it looks like the <code>TreeView</code> control may actually be more appropriate. You could have each combo box value show as a root-level node, and then inside each root-level node would be a child-node for each of the delimited values in the text box, like this:</p> <ul> <li>Premium <ul> <li>400</li> <li>500</li> <li>600</li> <li>700</li> </ul></li> <li>Cover <ul> <li>TPO</li> <li>TPFT</li> </ul></li> </ul>
    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. 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