locked
How do you Hyperlink a datagrid cell (for all values) to Pop-Up the Record Form ? RRS feed

  • Question

  • Before using Visual I created a front end for our database using Access ADP File. I was able to hyperlink all the ID Column cells to pop up their corresponding forms (previously created).

    I want to enable the same thing on the datagrid form in my windows front end app. 

    Any help would be greatly appreciated. I am very new to programming so the more detail the better :)


    Mike

    Monday, March 12, 2012 1:20 PM

Answers

  • Hello,

    Here is an example that shows how to work with a hyperlink column. In this case we are not data-bound but will work for data bound or non-databound columns.

    Public Class frmMainForm
        Private Sub Form1_Load( _
            ByVal sender As System.Object, _
            ByVal e As System.EventArgs) _
        Handles MyBase.Load
            Dim DataRows = _
            <Rows>
                <Row>
                    <Action>True</Action>
                    <Name>VB Forums</Name>
                    <Link>http://www.vbforums.com/</Link>
                </Row>
                <Row>
                    <Action>False</Action>
                    <Name>Google</Name>
                    <Link>http://www.google.com</Link>
                </Row>
                <Row>
                    <Action>True</Action>
                    <Name>Social forums</Name>
                    <Link>http://social.msdn.microsoft.com/</Link>
                </Row>
                <Row>
                    <Action>False</Action>
                    <Name>StackOverflow</Name>
                    <Link>http://stackoverflow.com/</Link>
                </Row>
                <Row>
                    <Action>True</Action>
                    <Name>Code Project</Name>
                    <Link>http://www.codeproject.com/</Link>
                </Row>
            </Rows>
            'http://stackoverflow.com/
            Dim Rows = _
            ( _
                From x In DataRows...<Row> _
                Select New With {.Action = x.<Action>.Value, .Name = x.<Name>.Value, .Link = x.<Link>.Value} _
            ).ToList
            Dim CheckColumn As New DataGridViewCheckBoxColumn With
                {
                    .DataPropertyName = "Action",
                    .Name = "ActionCol",
                    .HeaderText = "Action"
                }
            Dim NameColumn As New DataGridViewTextBoxColumn With
                {
                    .DataPropertyName = "Name",
                    .Name = "NameCol",
                    .HeaderText = "Name"
                }
            Dim LinkColumn As New DataGridViewLinkColumn With
                {
                    .DataPropertyName = "Link",
                    .Name = "LinkCol",
                    .HeaderText = "Link"
                }
            DataGridView1.Columns.AddRange(New DataGridViewColumn() _
                                           {CheckColumn, NameColumn, LinkColumn})
            DataGridView1.DataSource = Rows
            DataGridView1.Columns("LinkCol").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
        End Sub
        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
    End Class


    KSG

    • Proposed as answer by Helen Zhou Wednesday, March 14, 2012 8:13 AM
    • Marked as answer by Helen Zhou Tuesday, March 27, 2012 7:33 AM
    Monday, March 12, 2012 1:54 PM
  • Hi, 

    There were discussions on same point, 

    http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/3f53e654-3de3-4a88-8e91-6bcd6bf2d3d1

    http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/9abfaa04-7a10-43cf-93ea-0b479f52b5c2

    also check 

    DataGridViewLinkColumn


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

    • Proposed as answer by Helen Zhou Wednesday, March 14, 2012 8:16 AM
    • Marked as answer by Helen Zhou Tuesday, March 27, 2012 7:33 AM
    Tuesday, March 13, 2012 12:35 AM

All replies

  • Hello,

    Here is an example that shows how to work with a hyperlink column. In this case we are not data-bound but will work for data bound or non-databound columns.

    Public Class frmMainForm
        Private Sub Form1_Load( _
            ByVal sender As System.Object, _
            ByVal e As System.EventArgs) _
        Handles MyBase.Load
            Dim DataRows = _
            <Rows>
                <Row>
                    <Action>True</Action>
                    <Name>VB Forums</Name>
                    <Link>http://www.vbforums.com/</Link>
                </Row>
                <Row>
                    <Action>False</Action>
                    <Name>Google</Name>
                    <Link>http://www.google.com</Link>
                </Row>
                <Row>
                    <Action>True</Action>
                    <Name>Social forums</Name>
                    <Link>http://social.msdn.microsoft.com/</Link>
                </Row>
                <Row>
                    <Action>False</Action>
                    <Name>StackOverflow</Name>
                    <Link>http://stackoverflow.com/</Link>
                </Row>
                <Row>
                    <Action>True</Action>
                    <Name>Code Project</Name>
                    <Link>http://www.codeproject.com/</Link>
                </Row>
            </Rows>
            'http://stackoverflow.com/
            Dim Rows = _
            ( _
                From x In DataRows...<Row> _
                Select New With {.Action = x.<Action>.Value, .Name = x.<Name>.Value, .Link = x.<Link>.Value} _
            ).ToList
            Dim CheckColumn As New DataGridViewCheckBoxColumn With
                {
                    .DataPropertyName = "Action",
                    .Name = "ActionCol",
                    .HeaderText = "Action"
                }
            Dim NameColumn As New DataGridViewTextBoxColumn With
                {
                    .DataPropertyName = "Name",
                    .Name = "NameCol",
                    .HeaderText = "Name"
                }
            Dim LinkColumn As New DataGridViewLinkColumn With
                {
                    .DataPropertyName = "Link",
                    .Name = "LinkCol",
                    .HeaderText = "Link"
                }
            DataGridView1.Columns.AddRange(New DataGridViewColumn() _
                                           {CheckColumn, NameColumn, LinkColumn})
            DataGridView1.DataSource = Rows
            DataGridView1.Columns("LinkCol").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
        End Sub
        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
    End Class


    KSG

    • Proposed as answer by Helen Zhou Wednesday, March 14, 2012 8:13 AM
    • Marked as answer by Helen Zhou Tuesday, March 27, 2012 7:33 AM
    Monday, March 12, 2012 1:54 PM
  • Hi, 

    There were discussions on same point, 

    http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/3f53e654-3de3-4a88-8e91-6bcd6bf2d3d1

    http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/9abfaa04-7a10-43cf-93ea-0b479f52b5c2

    also check 

    DataGridViewLinkColumn


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

    • Proposed as answer by Helen Zhou Wednesday, March 14, 2012 8:16 AM
    • Marked as answer by Helen Zhou Tuesday, March 27, 2012 7:33 AM
    Tuesday, March 13, 2012 12:35 AM