Results 1 to 2 of 2

Thread: [RESOLVED] Can't show text from textbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    Resolved [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:

    Dim txt As Object
    For Each txt In frmMain.TabControl1.SelectedTab.Controls
    If TypeOf txt Is TextBox Then
    MsgBox(txt.Text)
    End If
    Last edited by vixez; Mar 27th, 2010 at 05:30 AM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width