whosyodaddy Posted June 24, 2003 Posted June 24, 2003 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. Quote
wyrd Posted June 24, 2003 Posted June 24, 2003 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistboxclassselecteditemtopic.asp Quote Gamer extraordinaire. Programmer wannabe.
whosyodaddy Posted June 24, 2003 Author Posted June 24, 2003 thanks for the link, that explains if something in the two box's are the same. but what about the Button?? Quote
whosyodaddy Posted June 24, 2003 Author Posted June 24, 2003 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!??! Quote
*Experts* Volte Posted June 24, 2003 *Experts* Posted June 24, 2003 (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 FunctionI 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 June 24, 2003 by Volte Quote
whosyodaddy Posted June 24, 2003 Author Posted June 24, 2003 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 ;-) Quote
*Experts* Volte Posted June 24, 2003 *Experts* Posted June 24, 2003 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)) Quote
whosyodaddy Posted June 24, 2003 Author Posted June 24, 2003 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. Quote
wyrd Posted June 24, 2003 Posted June 24, 2003 TextBox.Text += " " + Listbox1.SelectedItem.ToString(); Quote Gamer extraordinaire. Programmer wannabe.
Grimfort Posted June 25, 2003 Posted June 25, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.