This will hopefully be my last question for a while and with what i have gained from yourselves will help me really get on with this project! So... i currently have variosu combo boxes and text boxes being put into a list of strings on FORM2, all blanks ignored then output into list boxes on FORM3. this is my final piece.. combobox 1 will be populated with say "Premium", then textbox 1 will have 4 values "400,500,600,700" then combo box2 with "Cover" and textbox2 "TPO,TPFT,COMP"
i want it to look as follows any ---- are just for spacing out as it appears to ignore the spacebar
Listbox1 --- | --- ListBox2
Premium ------------ 400
-------------------------500
-------------------------600
-------------------------700
Cover-----------------TPO
-------------------------TPFT
etc etc.
what i am getting is
Listbox1 --- | --- ListBox2
Premium ------------ 400
Cover-----------------500
-------------------------600
-------------------------700
-------------------------TPO
-------------------------TPFT
there is no relation between the fields and i haven't a clue how to best describe or look-up how to do this, make it output combo box one, then textbox1 split into lines into a second box. then under these the next combo box etc. so i guess combobox + ((Textbox 1 lines -1 value) as blank lines) if i could put pictures up this would be so much easier! darnnn youu reputation!!!!
At last i can have pictures!!!!! As you can hopefully see, form 1 is irrelevant at the momemnt (will have no impact on the GUI for form2/3) but you pick various fields in form 2 and they ar mapped to form3 ATM some of the data is being mapped in a strange order. and there is no formatting between list 1 and 2
Find below a early concept of Form2 and Form3
This is what i am trying to do, the data is lay out in a readable format (and behind the scenes ran through various DROOLS that will morph the data and print the results of this).
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
ListBox
control is not well-suited for that, since it is designed for just showing a single column.Assuming this is a WinForm project, and not WPF, I would recommend using either a
DataGridView
control, or aListView
control. Either of those controls can show multiple columns, although, theListView
control only shows multiple columns with itsView
property is set toDetails
. Since I'm partial to theListView
control, myself, I'll give you an example using that one :)First, add a
ListView
control to your form. Then, set theView
property of the control, in the designer, toDetails
. Then click the button to edit theColumns
property of the control. Add two columns. Then, use code like this to populate the list: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:
Of course, rather than having a method like
GetTextBoxForComboBox
, it would be better to have have a class that stores the pairing of controls, like this:Then, you could just loop through them like this:
For Each
is a convenient syntax for iterating through all of the items in anIEnumerable
object (basically any list such as anArray
or aList(Of T)
). So, in this case, theMyPairs
would need to be a list ofControlPair
objects, for instance:Or, if you don't want to make your own class, you could just use
Tuple(Of ComboBox, TextBox)
.Actually, after seeing your screenshots, it looks like the
TreeView
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:Never rely on white space or blank lines for formatting. Write proper markup.