vb.net dynamic link lable











up vote
1
down vote

favorite












How can i find out which dynamic link has been clicked on Visual Basic? I have some LinkLabels created dynamically according to a dataset, and i want to open a new form that contains the information from that dataset, but i need to know how to load the form according to the link clicked.. code below...
//This function creates linklabels according to the rows in the datatable



Sub DynamicLabels()
Dim i As Integer
Dim x As Integer = 14
Dim y As Integer = 50
Dim tp As TabPage = tabControl1.TabPages(1)
If db.HasConnection() Then
If db.SQLDS IsNot Nothing Then
db.SQLDS.Clear()
End If
db.RunQuery("SELECT c.courseSubj AS Subject, c.courseNum AS CourseNum, r.className AS ClassName, t.tName AS Professor
FROM course c, classRoom r, teacher t, classroom_student u, student s
WHERE c.courseId=r.course_id AND t.teacherId=r.teacher_id AND s.studentId=u.student_id AND u.classroom_id=r.classId AND s.sUsername='" & Login.Usr.Text & "' ")
For i = 0 To db.SQLDS.Tables(0).Rows.Count - 1
ReDim MyLabel(db.SQLDS.Tables(0).Rows.Count)
y += 50
With MyLabel(i)
MyLabel(i) = New LinkLabel()
MyLabel(i).Name = "linklabel" & i.ToString
MyLabel(i).Location = New Point(x, y)
MyLabel(i).Size = New Size(700, 40)
MyLabel(i).Font = New Font("Microsoft Sans Serif", 14)
MyLabel(i).Text = String.Format(CType(db.SQLDS.Tables(0).Rows(i).Item("Subject"), String) & " " & CType(db.SQLDS.Tables(0).Rows(i).Item("CourseNum"), String) & " " & CType(db.SQLDS.Tables(0).Rows(i).Item("ClassName"), String) & ": " & CType(db.SQLDS.Tables(0).Rows(i).Item("Professor"), String))
AddHandler MyLabel(i).LinkClicked, AddressOf label_LinkClicked
End With
tp.Controls.Add(MyLabel(i))
Next
End If
End Sub


I want to load a new form containing some information from the dataset.










share|improve this question







New contributor




SpanishCode is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • The sender parameter in the clicked event tells you the instance. Cast it to a LinkLabel.
    – LarsTech
    Nov 21 at 18:55










  • Do i need to create a function with these parameters? how can i do that?
    – SpanishCode
    Nov 21 at 21:00










  • See VB.NET What is Sender used for?
    – LarsTech
    Nov 21 at 21:04










  • In your click event handler, just cast the sender like dim lbl as LinkLabel = ctype(sender, LinkLabel) and then you can access its Name() property that you have set...or just dim labelname as string = directcast(sender, linklabel).name
    – soohoonigan
    Nov 21 at 21:15












  • Why a LinkLabel? They are for displaying hyperlinks, internet URL's . How about a plain old Label?
    – Mary
    Nov 22 at 4:26















up vote
1
down vote

favorite












How can i find out which dynamic link has been clicked on Visual Basic? I have some LinkLabels created dynamically according to a dataset, and i want to open a new form that contains the information from that dataset, but i need to know how to load the form according to the link clicked.. code below...
//This function creates linklabels according to the rows in the datatable



Sub DynamicLabels()
Dim i As Integer
Dim x As Integer = 14
Dim y As Integer = 50
Dim tp As TabPage = tabControl1.TabPages(1)
If db.HasConnection() Then
If db.SQLDS IsNot Nothing Then
db.SQLDS.Clear()
End If
db.RunQuery("SELECT c.courseSubj AS Subject, c.courseNum AS CourseNum, r.className AS ClassName, t.tName AS Professor
FROM course c, classRoom r, teacher t, classroom_student u, student s
WHERE c.courseId=r.course_id AND t.teacherId=r.teacher_id AND s.studentId=u.student_id AND u.classroom_id=r.classId AND s.sUsername='" & Login.Usr.Text & "' ")
For i = 0 To db.SQLDS.Tables(0).Rows.Count - 1
ReDim MyLabel(db.SQLDS.Tables(0).Rows.Count)
y += 50
With MyLabel(i)
MyLabel(i) = New LinkLabel()
MyLabel(i).Name = "linklabel" & i.ToString
MyLabel(i).Location = New Point(x, y)
MyLabel(i).Size = New Size(700, 40)
MyLabel(i).Font = New Font("Microsoft Sans Serif", 14)
MyLabel(i).Text = String.Format(CType(db.SQLDS.Tables(0).Rows(i).Item("Subject"), String) & " " & CType(db.SQLDS.Tables(0).Rows(i).Item("CourseNum"), String) & " " & CType(db.SQLDS.Tables(0).Rows(i).Item("ClassName"), String) & ": " & CType(db.SQLDS.Tables(0).Rows(i).Item("Professor"), String))
AddHandler MyLabel(i).LinkClicked, AddressOf label_LinkClicked
End With
tp.Controls.Add(MyLabel(i))
Next
End If
End Sub


I want to load a new form containing some information from the dataset.










share|improve this question







New contributor




SpanishCode is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • The sender parameter in the clicked event tells you the instance. Cast it to a LinkLabel.
    – LarsTech
    Nov 21 at 18:55










  • Do i need to create a function with these parameters? how can i do that?
    – SpanishCode
    Nov 21 at 21:00










  • See VB.NET What is Sender used for?
    – LarsTech
    Nov 21 at 21:04










  • In your click event handler, just cast the sender like dim lbl as LinkLabel = ctype(sender, LinkLabel) and then you can access its Name() property that you have set...or just dim labelname as string = directcast(sender, linklabel).name
    – soohoonigan
    Nov 21 at 21:15












  • Why a LinkLabel? They are for displaying hyperlinks, internet URL's . How about a plain old Label?
    – Mary
    Nov 22 at 4:26













up vote
1
down vote

favorite









up vote
1
down vote

favorite











How can i find out which dynamic link has been clicked on Visual Basic? I have some LinkLabels created dynamically according to a dataset, and i want to open a new form that contains the information from that dataset, but i need to know how to load the form according to the link clicked.. code below...
//This function creates linklabels according to the rows in the datatable



Sub DynamicLabels()
Dim i As Integer
Dim x As Integer = 14
Dim y As Integer = 50
Dim tp As TabPage = tabControl1.TabPages(1)
If db.HasConnection() Then
If db.SQLDS IsNot Nothing Then
db.SQLDS.Clear()
End If
db.RunQuery("SELECT c.courseSubj AS Subject, c.courseNum AS CourseNum, r.className AS ClassName, t.tName AS Professor
FROM course c, classRoom r, teacher t, classroom_student u, student s
WHERE c.courseId=r.course_id AND t.teacherId=r.teacher_id AND s.studentId=u.student_id AND u.classroom_id=r.classId AND s.sUsername='" & Login.Usr.Text & "' ")
For i = 0 To db.SQLDS.Tables(0).Rows.Count - 1
ReDim MyLabel(db.SQLDS.Tables(0).Rows.Count)
y += 50
With MyLabel(i)
MyLabel(i) = New LinkLabel()
MyLabel(i).Name = "linklabel" & i.ToString
MyLabel(i).Location = New Point(x, y)
MyLabel(i).Size = New Size(700, 40)
MyLabel(i).Font = New Font("Microsoft Sans Serif", 14)
MyLabel(i).Text = String.Format(CType(db.SQLDS.Tables(0).Rows(i).Item("Subject"), String) & " " & CType(db.SQLDS.Tables(0).Rows(i).Item("CourseNum"), String) & " " & CType(db.SQLDS.Tables(0).Rows(i).Item("ClassName"), String) & ": " & CType(db.SQLDS.Tables(0).Rows(i).Item("Professor"), String))
AddHandler MyLabel(i).LinkClicked, AddressOf label_LinkClicked
End With
tp.Controls.Add(MyLabel(i))
Next
End If
End Sub


I want to load a new form containing some information from the dataset.










share|improve this question







New contributor




SpanishCode is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











How can i find out which dynamic link has been clicked on Visual Basic? I have some LinkLabels created dynamically according to a dataset, and i want to open a new form that contains the information from that dataset, but i need to know how to load the form according to the link clicked.. code below...
//This function creates linklabels according to the rows in the datatable



Sub DynamicLabels()
Dim i As Integer
Dim x As Integer = 14
Dim y As Integer = 50
Dim tp As TabPage = tabControl1.TabPages(1)
If db.HasConnection() Then
If db.SQLDS IsNot Nothing Then
db.SQLDS.Clear()
End If
db.RunQuery("SELECT c.courseSubj AS Subject, c.courseNum AS CourseNum, r.className AS ClassName, t.tName AS Professor
FROM course c, classRoom r, teacher t, classroom_student u, student s
WHERE c.courseId=r.course_id AND t.teacherId=r.teacher_id AND s.studentId=u.student_id AND u.classroom_id=r.classId AND s.sUsername='" & Login.Usr.Text & "' ")
For i = 0 To db.SQLDS.Tables(0).Rows.Count - 1
ReDim MyLabel(db.SQLDS.Tables(0).Rows.Count)
y += 50
With MyLabel(i)
MyLabel(i) = New LinkLabel()
MyLabel(i).Name = "linklabel" & i.ToString
MyLabel(i).Location = New Point(x, y)
MyLabel(i).Size = New Size(700, 40)
MyLabel(i).Font = New Font("Microsoft Sans Serif", 14)
MyLabel(i).Text = String.Format(CType(db.SQLDS.Tables(0).Rows(i).Item("Subject"), String) & " " & CType(db.SQLDS.Tables(0).Rows(i).Item("CourseNum"), String) & " " & CType(db.SQLDS.Tables(0).Rows(i).Item("ClassName"), String) & ": " & CType(db.SQLDS.Tables(0).Rows(i).Item("Professor"), String))
AddHandler MyLabel(i).LinkClicked, AddressOf label_LinkClicked
End With
tp.Controls.Add(MyLabel(i))
Next
End If
End Sub


I want to load a new form containing some information from the dataset.







vb.net linklabel






share|improve this question







New contributor




SpanishCode is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




SpanishCode is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




SpanishCode is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 21 at 18:51









SpanishCode

61




61




New contributor




SpanishCode is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





SpanishCode is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






SpanishCode is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • The sender parameter in the clicked event tells you the instance. Cast it to a LinkLabel.
    – LarsTech
    Nov 21 at 18:55










  • Do i need to create a function with these parameters? how can i do that?
    – SpanishCode
    Nov 21 at 21:00










  • See VB.NET What is Sender used for?
    – LarsTech
    Nov 21 at 21:04










  • In your click event handler, just cast the sender like dim lbl as LinkLabel = ctype(sender, LinkLabel) and then you can access its Name() property that you have set...or just dim labelname as string = directcast(sender, linklabel).name
    – soohoonigan
    Nov 21 at 21:15












  • Why a LinkLabel? They are for displaying hyperlinks, internet URL's . How about a plain old Label?
    – Mary
    Nov 22 at 4:26


















  • The sender parameter in the clicked event tells you the instance. Cast it to a LinkLabel.
    – LarsTech
    Nov 21 at 18:55










  • Do i need to create a function with these parameters? how can i do that?
    – SpanishCode
    Nov 21 at 21:00










  • See VB.NET What is Sender used for?
    – LarsTech
    Nov 21 at 21:04










  • In your click event handler, just cast the sender like dim lbl as LinkLabel = ctype(sender, LinkLabel) and then you can access its Name() property that you have set...or just dim labelname as string = directcast(sender, linklabel).name
    – soohoonigan
    Nov 21 at 21:15












  • Why a LinkLabel? They are for displaying hyperlinks, internet URL's . How about a plain old Label?
    – Mary
    Nov 22 at 4:26
















The sender parameter in the clicked event tells you the instance. Cast it to a LinkLabel.
– LarsTech
Nov 21 at 18:55




The sender parameter in the clicked event tells you the instance. Cast it to a LinkLabel.
– LarsTech
Nov 21 at 18:55












Do i need to create a function with these parameters? how can i do that?
– SpanishCode
Nov 21 at 21:00




Do i need to create a function with these parameters? how can i do that?
– SpanishCode
Nov 21 at 21:00












See VB.NET What is Sender used for?
– LarsTech
Nov 21 at 21:04




See VB.NET What is Sender used for?
– LarsTech
Nov 21 at 21:04












In your click event handler, just cast the sender like dim lbl as LinkLabel = ctype(sender, LinkLabel) and then you can access its Name() property that you have set...or just dim labelname as string = directcast(sender, linklabel).name
– soohoonigan
Nov 21 at 21:15






In your click event handler, just cast the sender like dim lbl as LinkLabel = ctype(sender, LinkLabel) and then you can access its Name() property that you have set...or just dim labelname as string = directcast(sender, linklabel).name
– soohoonigan
Nov 21 at 21:15














Why a LinkLabel? They are for displaying hyperlinks, internet URL's . How about a plain old Label?
– Mary
Nov 22 at 4:26




Why a LinkLabel? They are for displaying hyperlinks, internet URL's . How about a plain old Label?
– Mary
Nov 22 at 4:26












1 Answer
1






active

oldest

votes

















up vote
0
down vote













I just added one label to demonstrate. Each Label you add would have the same Event procedure (the AddressOf part) but the Add Handler refers directly to the new label variable (mylabel.Click)



Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim mylabel As New Label With {
.Text = "New Label",
.Name = "newLabel",
.Location = New Point(400, 100)
}
AddHandler mylabel.Click, AddressOf aLabel_Click
Controls.Add(mylabel)
End Sub


And here is your event procedure



Private Sub aLabel_Click(sender As Object, e As EventArgs)
Dim EventLabel As Label = DirectCast(sender, Label)
Dim LabelText As String = EventLabel.Text
'or any other property of the label you need to use
MessageBox.Show(LabelText)
End Sub





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    SpanishCode is a new contributor. Be nice, and check out our Code of Conduct.










     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418789%2fvb-net-dynamic-link-lable%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    I just added one label to demonstrate. Each Label you add would have the same Event procedure (the AddressOf part) but the Add Handler refers directly to the new label variable (mylabel.Click)



    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim mylabel As New Label With {
    .Text = "New Label",
    .Name = "newLabel",
    .Location = New Point(400, 100)
    }
    AddHandler mylabel.Click, AddressOf aLabel_Click
    Controls.Add(mylabel)
    End Sub


    And here is your event procedure



    Private Sub aLabel_Click(sender As Object, e As EventArgs)
    Dim EventLabel As Label = DirectCast(sender, Label)
    Dim LabelText As String = EventLabel.Text
    'or any other property of the label you need to use
    MessageBox.Show(LabelText)
    End Sub





    share|improve this answer

























      up vote
      0
      down vote













      I just added one label to demonstrate. Each Label you add would have the same Event procedure (the AddressOf part) but the Add Handler refers directly to the new label variable (mylabel.Click)



      Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      Dim mylabel As New Label With {
      .Text = "New Label",
      .Name = "newLabel",
      .Location = New Point(400, 100)
      }
      AddHandler mylabel.Click, AddressOf aLabel_Click
      Controls.Add(mylabel)
      End Sub


      And here is your event procedure



      Private Sub aLabel_Click(sender As Object, e As EventArgs)
      Dim EventLabel As Label = DirectCast(sender, Label)
      Dim LabelText As String = EventLabel.Text
      'or any other property of the label you need to use
      MessageBox.Show(LabelText)
      End Sub





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        I just added one label to demonstrate. Each Label you add would have the same Event procedure (the AddressOf part) but the Add Handler refers directly to the new label variable (mylabel.Click)



        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim mylabel As New Label With {
        .Text = "New Label",
        .Name = "newLabel",
        .Location = New Point(400, 100)
        }
        AddHandler mylabel.Click, AddressOf aLabel_Click
        Controls.Add(mylabel)
        End Sub


        And here is your event procedure



        Private Sub aLabel_Click(sender As Object, e As EventArgs)
        Dim EventLabel As Label = DirectCast(sender, Label)
        Dim LabelText As String = EventLabel.Text
        'or any other property of the label you need to use
        MessageBox.Show(LabelText)
        End Sub





        share|improve this answer












        I just added one label to demonstrate. Each Label you add would have the same Event procedure (the AddressOf part) but the Add Handler refers directly to the new label variable (mylabel.Click)



        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim mylabel As New Label With {
        .Text = "New Label",
        .Name = "newLabel",
        .Location = New Point(400, 100)
        }
        AddHandler mylabel.Click, AddressOf aLabel_Click
        Controls.Add(mylabel)
        End Sub


        And here is your event procedure



        Private Sub aLabel_Click(sender As Object, e As EventArgs)
        Dim EventLabel As Label = DirectCast(sender, Label)
        Dim LabelText As String = EventLabel.Text
        'or any other property of the label you need to use
        MessageBox.Show(LabelText)
        End Sub






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 5:34









        Mary

        2,6032618




        2,6032618






















            SpanishCode is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            SpanishCode is a new contributor. Be nice, and check out our Code of Conduct.













            SpanishCode is a new contributor. Be nice, and check out our Code of Conduct.












            SpanishCode is a new contributor. Be nice, and check out our Code of Conduct.















             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418789%2fvb-net-dynamic-link-lable%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Trompette piccolo

            Slow SSRS Report in dynamic grouping and multiple parameters

            Simon Yates (cyclisme)