07-27-2011, 07:05 AM
Ok. I took another look at it and think I found a solution.
In order for this to work I will need to tell you a little about index's. If you already know about these, you can skip this section. If you add an item to a listbox, It gets an index number. An index number is like an ID number. No two items in the same listbox get the same index number. The first item added to the listbox gets and index of 0. The second item added to the listbox get an index of 1. The index increases each time you add a new item to the listbox. We will use the index numbers to see what item is selected in the listbox.
Now that is out of the way, lets get to work. Delete the sub with the webbrowser text change. No need to have extra code. Also delete the KryptonListBox1_TextChanged sub. It is not needed and is not a real event. (Don't worry about events yet).
Now lets add the code:
This is where the magic happens and the webbrowser's text changes.
Hope this one fixes those errors.
In order for this to work I will need to tell you a little about index's. If you already know about these, you can skip this section. If you add an item to a listbox, It gets an index number. An index number is like an ID number. No two items in the same listbox get the same index number. The first item added to the listbox gets and index of 0. The second item added to the listbox get an index of 1. The index increases each time you add a new item to the listbox. We will use the index numbers to see what item is selected in the listbox.
Now that is out of the way, lets get to work. Delete the sub with the webbrowser text change. No need to have extra code. Also delete the KryptonListBox1_TextChanged sub. It is not needed and is not a real event. (Don't worry about events yet).
Now lets add the code:
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Add as many items to the listbox you want
KryptonListBox1.Items.Add("PIE")'First item. Index: 0
KryptonListBox1.Items.Add("ages")' second item. Index: 1
KryptonListBox1.Items.Add("VB 2010")'Third Item. Index: 2
End Sub
Code:
Private Sub KryptonButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KryptonButton1.Click
If KryptonListBox1.SelectedIndex = 0 Then 'the first item added to the listbox
WebBrowser1.DocumentText = "PIE - 'A tasty desert'"
ElseIf KryptonListBox1.SelectedIndex = 1 Then 'the second item added to the listbox
WebBrowser1.DocumentText = "A long time - 'It took ages!'"
ElseIf KryptonListBox1.SelectedIndex = 2 Then 'the third item added to the listbox
WebBrowser1.DocumentText = "The application your writing this in"
End If
End Sub
Hope this one fixes those errors.
--VBCodeGeek--