none
For each link label value to open RRS feed

  • Question

  • Hey , I have code to makes new label for each row in DataGridView to show in form and each row have link to open file power point .. i want to be each link label have value when i click on it open file where source in row in datagridview ???
     newconnection.Open()
            Dim DataAdapter1 As New OleDbDataAdapter(SQLstr, newconnection)
            DataAdapter1.Fill(DataSet1, "TableA")
            newconnection.Close()
    
    
            DataGridView1.DataSource = DataSet1
            DataGridView1.DataMember = "TableA"
            DataGridView1.AllowDrop = True
            Dim x, y As Integer
            x = 600
            y = 300
            For Each r As DataGridViewRow In DataGridView1.Rows
                If r.IsNewRow = True Then
                    Return
                End If
                Dim new_label1 As New Label()
                With r
                    new_label1.Text = .Cells("Name").Value.ToString
                    new_label1.Location = New Point(x, y)
                    new_label1.BringToFront()
                    Me.Controls.Add(new_label1)
                    'x += 10
                    y += new_label1.Height + 10
                End With
            Next
    
            Dim a, b As Integer
            a = 300
            b = 300
    
            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

    and that's image you can helped by it
    Wednesday, April 3, 2013 10:15 PM

Answers

All replies

  • For the DataGridView

        Private Sub DataGridView1_CellContentClick( _
            ByVal sender As Object, _
            ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
            If TypeOf DataGridView1.Columns(e.ColumnIndex) Is DataGridViewLinkColumn AndAlso Not e.RowIndex = -1 Then
                Process.Start(DataGridView1.Item(e.ColumnIndex, e.RowIndex).Value.ToString())
            End If
        End Sub

    For the LinkLabel you need to have a mouse click event attached to the label using AddHandler when creating the label.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Thursday, April 4, 2013 8:24 PM
    Moderator
  • No i don't want to this code .. But i want to explain more what's i can do to the link labels because i will hide DGV from the form ..


    Thanks ,

    Shady ,,

    Thursday, April 4, 2013 10:55 PM
    • Why use a DataGridView then hide it?
    • Why did you not indicate hiding the DataGridView in your original questions?

    I did respond to your question on link labels at the end of my reply. Did you look at the MSDN documentation which has a good example. For AddHandler, again MSDN documentation is excellent. Many LinkLabel controls can share one event as per above information.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Friday, April 5, 2013 2:34 AM
    Moderator
  • Why use a DataGridView then hide it?

    Because This form to search .. How i can put the DataGridView in from !!!
    ----------------------------------------
    Why did you not indicate hiding the DataGridView in your original questions?
    To Explain more

    ----------------------------------------
    My problem when i click on first link label .. Open all of files not the first only .. And when i click on the second and third .... etc no files open

    That's my question .. How to open file by clicking on the first link label by the text in it ??  And how open anther file by clicking on the second link label by the text in it ??????????

    Friday, April 5, 2013 8:34 AM
  • Hello,

    I would reconsider the logic for what you are attempting to do. Ask yourself, how many applications have you seen where the application hides a grid? I have seen exactly zero applications do this. In addition, whether the user tells you or not my guess is this is confusing to them.  Using your current logic, I cannot assist you as it is truly a unwise avenue to go.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Friday, April 5, 2013 11:40 AM
    Moderator
  • Then , How i can 1 - make connect the app with access , 2 - search on word in the column name is "Layers" , 3 - show the values of column " Link " in DGV  by link label , 4 - open the link by click on it ????????????????????????????

    Any Body can help me ??

    Thanks
    Shady,,
    Friday, April 5, 2013 2:50 PM
  • Hi Shady,

    1, you can use the .NET Framework Provider for OleDB. 

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

    http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection.aspx

    http://www.codeproject.com/Articles/8269/How-to-link-to-an-Access-Database-in-a-C-Applicati

    2.you doesn't need to search column name, just use DataGridViewColumnCollection.Item Property (String).

    3,to show link in DataGridView, you can use DataGridViewLinkColumn Class.

    4.the link in datagridviewlinkcell will open when you click on it.

    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.


    Monday, April 8, 2013 7:45 AM
    Moderator