Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Hello everybody. I need some help to finish creating this project of mine. I have one Listbox, named Listbox1, a button, named Button1, and another Listbox, named Listbox2. When a user clicks on a certain text in Listbox1, then clicks Button1, how do i make it so that certain text comes up in Listbox2? For example: There are 5 different things listed in Listbox1, i select one of them, then click Button1, and then certain text for the thing i selected in Listbox1 comes up in Listbox2. How do i do this? If you give me code please tell me where to put it. Thank you! Help would be appreciated over and beyond.
Posted
you mustve not read clearly, what about when clicking on something in Listbox1, for example "Cat" in listbox1, then press the button, then "Dog" appears in Listbox2. HOW!??!
  • *Experts*
Posted (edited)
You could store the two things in two arrays:
Dim stuff1 As String() = New String() {"Dog", "Up", "Black", "Day", "On"}
Dim stuff2 As String() = New String() {"Cat", "Down", "White", "Night", "Off"}

Then you find the position of the word you want in the first array, and use that position to extract the word from the second array. For example:

Private Function FindOpposite(word As String) As String
 Dim position As Integer = Array.IndexOf(stuff1, word)
 
 If position >= 0 Then
   Return stuff2(position)
 Else
   Return ""
 End If
End Function

I believe something like that will work. For example, FindOpposite("Up") will return "Down", etc. Just make sure that the two corresponding words in the arrays are at the same position; for example, "Day" and "Night" are both at position 4 in the two arrays.

Edited by Volte
Posted

im sorry to say that all of you were wrong.

 

here is the right code i needed:

 

Dim s As String

Dim i As Integer

 

ListBox2.Items.Clear()

i = ListBox1.SelectedIndex()

s = ListBox1.SelectedItem()

 

' this is a test

If (s.Equals("Something")) Then

ListBox2().Items.Add("What Something?")

ElseIf (s.Equals("007 Agent Under Fire")) Then

ListBox2().Items.Add("Bam!")

End If

 

so just incase somebody asks a similiar question you can answer it right ;-)

  • *Experts*
Posted

Actually, the code I posted is much more efficient, and easier to expand. You just need to make sure not to add "" to the listbox if necessary, and it will work exactly how you want.

 

If the elements in stuff1 are "Something" and "007 Agent Under Fire", and the elements in stuff2 are "What Something" and "Bam!", it will work the way you posted.

 

Just do

List2.Items.Add(FindOpposite(s))

Posted

well, i changed listbox2 to a textbox. i have the code and stuff. i am going to be making over 500 selections in Listbox1, and about 2 paragraphs text that will appear in Textbox1 for EACH selection in Listbox1. what would be the easiest method (code) for this? im not just doing one word like "dog" and "white". its more like this length:

 

"muchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewordsmuchmorewords".

 

so please help and tell what you would do.

Posted

The answer you have found, hardly matches your actual description for what you wanted. Its just hard coded IF statments rather then dynamic arrays for multiple links for multiple results.

 

There are people in this forum who could boggle your brain with what they know about coding.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...