none
for each new link label prosses to do RRS feed

  • Question

  • i have this code

            For Each r As DataGridViewRow In DataGridView1.Rows
                If r.IsNewRow = True Then
                    Return
                End If
                Dim new_label2 As New LinkLabel
                With r
                    new_label2.Text = .Cells("Link").Value.ToString
                    new_label2.Location = New Point(a, b)
                    new_label2.BringToFront()
                    Me.Controls.Add(new_label2)
                    'a += 10
                    b += new_label2.Height + 10
                End With
            Next

    I have viable of DataGridView is false , I want this .

    The all of new_label2 is links to open powerpoint show.

    -------------------------------

    How i can click on the first new_label2 and show me the powerpoint where the source of file is in link ???

    and when click on the second new_label2 show me the powerpoint where the source of file is in link ???

    Thaks ..

    Shady,

    Tuesday, April 9, 2013 11:48 PM

Answers

  • Hi Shady,

    When you make a label, please add the event handler at the same time:

    For Each r As DataGridViewRow In DataGridView1.Rows If r.IsNewRow = True Then Return End If Dim new_label2 As New LinkLabel With r new_label2.Text = .Cells("Link").Value.ToString new_label2.Location = New Point(a, b) new_label2.Links.add(0,.Cells("Link").Value.ToString.length,.Cells("Link").Value.ToString)

    new_label2.BringToFront() Addhandler new_label2.LinkClicked, AddressOf LableLinkClicked Me.Controls.Add(new_label2) 'a += 10 b += new_label2.Height + 10 End With Next


    In the handler, you can put the link in the process.start(""): http://msdn.microsoft.com/en-us/library/system.windows.forms.linklabellinkclickedeventargs.link.aspx  

    And you need to set the links property in above code: http://msdn.microsoft.com/en-us/library/system.windows.forms.linklabel.links.aspx 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Sunday, May 5, 2013 5:39 AM
    Moderator
  • Hi Shady,

    My bad, please try this code:

    new_label2.Links.add(0,.Cells("Link").Value.ToString.length,.Cells("Link").Value.ToString)

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Shady Boshra Tuesday, May 14, 2013 11:59 AM
    Tuesday, May 14, 2013 8:29 AM
    Moderator
  • Hi Shady,

    You cannot directly use the local variable in another function.

    Please try this: 

    Public Sub EventHandler (ByVal Sender As Sstem.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
            Dim ll As LinkLabel = DirectCast(sender, LinkLabel)
            Process.Start(ll.text)
    
    End Sub

    Actually, you need to use the link data like this:

    Public Sub EventHandler (ByVal Sender As Sstem.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
            ' Displays the appropriate link based on the value of the LinkData property of the Link object. 
            Dim target As String = CType(e.Link.LinkData, String)
    
            ' If the value looks like a URL, navigate to it. 
            ' Otherwise, display it in a message box. 
            If (target IsNot Nothing) AndAlso (target.StartsWith("www")) Then
                System.Diagnostics.Process.Start(target)
            Else
                MessageBox.Show(("Item clicked: " + target))
            End If 
    
    End Sub

    I hope this is clear.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Shady Boshra Tuesday, May 14, 2013 11:58 AM
    Tuesday, May 14, 2013 11:45 AM
    Moderator

All replies

  • Hi Shady,

    You need to handle LinkLabel.LinkClicked Event, see 

    http://msdn.microsoft.com/en-us/library/system.windows.forms.linklabel.linkclicked.aspx

    http://msdn.microsoft.com/en-us/library/f6hya464.aspx

    Best Regards,


    Bob Wu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 10, 2013 8:24 AM
    Moderator

  • Sorry , But i can't apply this because when i write ( new_label2 ) in code out the sub where code is

            For Each r As DataGridViewRow In DataGridView1.Rows
                If r.IsNewRow = True Then
                    Return
                End If
                Dim new_label2 As New LinkLabel
                With r
                    new_label2.Text = .Cells("Link").Value.ToString
                    new_label2.Location = New Point(a, b)
                    new_label2.BringToFront()
                    Me.Controls.Add(new_label2)
                    'a += 10
                    b += new_label2.Height + 10
                End With
            Next

    Show me is not right and don't work the application 

    Thanks.

    Shady,

    Wednesday, April 10, 2013 11:35 AM
  • Who can heeeeeeeeeeeelp me ??
    Friday, April 12, 2013 12:53 AM
  • Hi Shady,

    Did you add LinkLabel.LinkClicked Event handler for each LinkLabel?

    http://msdn.microsoft.com/en-us/library/6yyk8z93(v=vs.90).aspx

    Does the event raised when you click the link?

    Could you please show us your current code and current result?

    Best Regards,


    Bob Wu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, April 12, 2013 7:11 AM
    Moderator
  • Thanks a lot , I did put the Event handler to my code .. but i have two problems for now
    My first problem : my form when show me the new_label2 as label link .. i see 5 label links ..  but name of all label links is new_label2
    and when i put in add handler you talk about this code

    Process.Start("")


    I don't know what are i will put between ""

    My second problem : If i put in ""

    dim o as string
    o = new_label2.text

    show me wrong with new_label2

    and anther problem is new_label2 mean alllll of label links .. and when i click on the one of them open all of process is open power point files 

    What's can i do now ??

    Thanks ..
    Shady ,

    Saturday, April 13, 2013 12:12 PM
  •  Where's the answers ?!
    Sunday, April 14, 2013 9:22 PM
  • No one can help me please ???
    Tuesday, April 16, 2013 3:54 PM
  • Hi Shady,

    When you make a label, please add the event handler at the same time:

    For Each r As DataGridViewRow In DataGridView1.Rows If r.IsNewRow = True Then Return End If Dim new_label2 As New LinkLabel With r new_label2.Text = .Cells("Link").Value.ToString new_label2.Location = New Point(a, b) new_label2.Links.add(0,.Cells("Link").Value.ToString.length,.Cells("Link").Value.ToString)

    new_label2.BringToFront() Addhandler new_label2.LinkClicked, AddressOf LableLinkClicked Me.Controls.Add(new_label2) 'a += 10 b += new_label2.Height + 10 End With Next


    In the handler, you can put the link in the process.start(""): http://msdn.microsoft.com/en-us/library/system.windows.forms.linklabellinkclickedeventargs.link.aspx  

    And you need to set the links property in above code: http://msdn.microsoft.com/en-us/library/system.windows.forms.linklabel.links.aspx 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Sunday, May 5, 2013 5:39 AM
    Moderator
  • Thanks for your wonderfully answer .. but i have 2 problem 

    First : I have a Error in

    new_label2.Links.add(.Cells("Link").Value.ToString)

    The error is " Value of type 'string' cannot be converted to ' System .Windows.Forms.LinkLabel.Link "
    ---------------------------

    Second : I don't understand what i must do by this " And you need to set the links property in above code: http://msdn.microsoft.com/en-us/library/system.windows.forms.linklabel.links.aspx  "
    I don't know where i must put it !!

    And thanks again

    Shady,,

    Sunday, May 12, 2013 11:29 PM
  • Hi Shady,

    My bad, please try this code:

    new_label2.Links.add(0,.Cells("Link").Value.ToString.length,.Cells("Link").Value.ToString)

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Shady Boshra Tuesday, May 14, 2013 11:59 AM
    Tuesday, May 14, 2013 8:29 AM
    Moderator
  • Thanks for your answer ,

    But when i put this code

    Public Sub EventHandler (ByVal Sender As Sstem.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
    
    Process.Start(new_label2.text)
    
    End Sub

    It's say Error : " Name 'new_label2' is not declared "

    Thanks Again

    Shady,,

    Tuesday, May 14, 2013 10:09 AM
  • Hi Shady,

    You cannot directly use the local variable in another function.

    Please try this: 

    Public Sub EventHandler (ByVal Sender As Sstem.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
            Dim ll As LinkLabel = DirectCast(sender, LinkLabel)
            Process.Start(ll.text)
    
    End Sub

    Actually, you need to use the link data like this:

    Public Sub EventHandler (ByVal Sender As Sstem.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
            ' Displays the appropriate link based on the value of the LinkData property of the Link object. 
            Dim target As String = CType(e.Link.LinkData, String)
    
            ' If the value looks like a URL, navigate to it. 
            ' Otherwise, display it in a message box. 
            If (target IsNot Nothing) AndAlso (target.StartsWith("www")) Then
                System.Diagnostics.Process.Start(target)
            Else
                MessageBox.Show(("Item clicked: " + target))
            End If 
    
    End Sub

    I hope this is clear.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Shady Boshra Tuesday, May 14, 2013 11:58 AM
    Tuesday, May 14, 2013 11:45 AM
    Moderator
  • Oh my god .. It's Worked .. Thank you very much

    Mark As Answer

    Thanks again

    Shady,,

    Tuesday, May 14, 2013 11:58 AM
  • So .. I want now to remove the new_label2 from form .. When form is running

    Shady ,,
    Tuesday, May 14, 2013 1:05 PM
  • So .. I want now to remove the new_label2 from form .. When form is running

    Shady ,,

    Hi Shady,

    So you encounter a new issue? If so, make a new thread for this question.

    Thanks.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 14, 2013 1:20 PM
    Moderator