07-31-2011, 05:32 AM
brandonio21 Wrote:Hello,
Sorry for not replying until this thread seems to be completely full.
First of all, there is no need to mess around with indexes and such, that may just make your code more confusing. It is much easier just to go straight for the actual text of the listbox item.
So here is some code that should work, it has been tested to work on my system.
Code:Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Items.Add("Pie")
ListBox1.Items.Add("Keyboard")
ListBox1.Items.Add("Shoes")
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
'First, we clear the exisitng WebBrowser text
WebBrowser1.DocumentText = ""
'Then, we set the new text
writeWebBrowser()
If WebBrowser1.DocumentText Is Nothing Then
writeWebBrowser()
Else
Trace.TraceError("Error.")
End If
End Sub
Sub writeWebBrowser()
If ListBox1.SelectedItem.ToString = "Pie" Then WebBrowser1.DocumentText = "Pie - A tasty treat"
If ListBox1.SelectedItem.ToString = "Keyboard" Then WebBrowser1.DocumentText = "Keyboard - Quite literally, a board of keys"
If ListBox1.SelectedItem.ToString = "Shoes" Then WebBrowser1.DocumentText = "Shoes - A huge problem facing our communities... Not really."
End Sub
End Class
Sorry if this is hard to understand, but it is very simple. With this code, the listbox has to be clicked a couple of times....
Please tell me if this works or not. And remember to adjust the element names in the code to your elements!!
You are a legend. Thank you so much. Works perfectly. <!-- shock: --><img src="{SMILIES_PATH}/icon_eek.gif" alt="hock:" title="Shocked" /><!-- shock: -->