[RESOLVED] Can't show text from textbox
Hey,
In my tabcontrol I have a linklabel and textbox made through code.
The goal is to open a url from the textbox by clicking the linklabel
I add the linklabel and textbox:
Code:
Dim lblLink As New LinkLabel
Dim txtLink As New TextBox
AddHandler lblLink.Click, AddressOf lblLinkClick
lblLink.Text = "Link: " & matchLink.Groups(1).Value
txtLink.Text = matchLink.Groups(1).Value
This is the code that is run when clicking on the linklabel
Code:
Private Sub lblLinkClick()
Dim txt As TextBox
For Each txt In frmMain.TabControl1.SelectedTab.Controls
MsgBox(txt.Text)
Next
When I run the code it highlights the For Each line, and gives this error:
Unable to cast object of type 'System.Windows.Forms.Label' to type 'System.Windows.Forms.TextBox'.
How can I fix this?
End Sub
Edit:
nevermind, I solved it.
I reaplced to lblLinkClick code to this:
Quote:
Dim txt As Object
For Each txt In frmMain.TabControl1.SelectedTab.Controls
If TypeOf txt Is TextBox Then
MsgBox(txt.Text)
End If
Re: Can't show text from textbox
Well, what did you expect? You're looping through all of the controls.... and yes, you can't coerce a linklabel into a text box. If you need to loop through the controls, you need a control object, then you'll need to check the TypeOf on the control to see if it's a text box. That said, if you only have one text box there isn't a point in looping.
-tg