|
-
Dec 16th, 2015, 10:55 AM
#1
Thread Starter
New Member
Adding text between listboxes items
I'm using vb.net form.
I have 8 listboxes (listbox1 , listbox2,listbox3..) each one contains many items and another empty listbox (listbox10). I'm trying to add first listboxes items into the listbox10
ex: listbox1 first items is "A" , listbox2 first items is "B" , listbox3 first items is "C"...etc . Now listbox10 first item must be "Abc...";
The problem is i want to add text ( string or number) between each listbox
ex: listbox1 first items is "A" , listbox2 first items is "B" , listbox3 first items is "C"...etc . Now I want listbox10 first item to be "The letters A is before B and now C"
The main idea is to combine all listboxes items and adding text between them to create a meaningful sentence
here is my code
Dim controls = New List(Of ListBox)() From _
{ListBox1, ListBox2, ListBox3, ListBox4, ListBox5, ListBox6, ListBox7, ListBox8}
Dim minCount = Controls.Min(Function(x) x.Items.Count)
For x = 1 To minCount - 1
ListBox10.Items.Add(String.Join(" ", controls.Select
(Function(lb) lb.Items(x).ToString)))
Next
End Sub
-
Dec 16th, 2015, 08:11 PM
#2
Re: Adding text between listboxes items
This question really has nothing at all to do with ListBoxes. It boils down to the fact that you have a number of Strings and you want to build another String from them and some literal text. That is an example of how you identify what the actual problem is and not make it harder to solve by including irrelevant factors. It's for that sort of thing that the String.Format method exists. As a simple example:
vb.net Code:
Dim text = String.Format("The name is {0}. {1} {0}.",
familyNameTextBox.Text,
givenNameTextBox.Text)
If the user were to type "James" into the given name field and "Bond" into the family name field then `text` would contain "The name is Bond. James Bond.". As you can see, it's simple to insert whatever values you want into literal text wherever you want.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|