Results 1 to 13 of 13

Thread: Vb.Net 2005 - Defining a DGV Column as LinkCell???

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Vb.Net 2005 - Defining a DGV Column as LinkCell???

    I am trying to define a column in a DataGridView as a LinkCell and I keep getting the following error:

    "Value provided for cell template must of type 'Windows.System.Forms.DataGridViewTextBoxCell' or derive from it"

    I've included my code:
    Code:
        Private Sub FormatGrid3()
            Try
                grd3.RowHeadersVisible = False
    
                grd3.Columns(0).Width = 100
                grd3.Columns(0).HeaderText = "Request ID"
    
                grd3.Columns(1).Width = 140
                grd3.Columns(1).CellTemplate = New DataGridViewLinkCell
                grd3.Columns(1).HeaderText = "Image Name"
    
                grd3.Columns(2).Width = 430
                grd3.Columns(2).HeaderText = "File Path"
    
            Catch ex As Exception
                ErrorHandler(strModule, strProcedure, Msg)
            End Try
        End Sub
    Blake

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???

    You can't change the type of a column once it's been created. If you are relying on the grid to create the columns for you then it's going to create text box columns in most cases as that's the default type for most data types. If you want a column of hyperlinks then you'll have to create that column yourself, either in code or, more likely, in the designer. You set the column's DataPropertyName to specify that it should bind to a specific column in the data source.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???

    Ok,

    I got it working...but when I click/doubleclick on the filename (linked cell)...nothing happens. I thought that because it is defined as a LinkCell that it would automatically associate an application to open the link.
    Last edited by blakemckenna; Jul 3rd, 2007 at 09:27 AM.
    Blake

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???

    If you had read the MSDN documentation for the DataGridViewLinkColumn class you would already have your answer.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???

    I did a search using VS Help and all I got was the following:

    Code:
    Private Sub AddLinkColumn()
    
        Dim links As New DataGridViewLinkColumn()
        With links
            .HeaderText = ColumnName.ReportsTo.ToString()
            .DataPropertyName = ColumnName.ReportsTo.ToString()
            .ActiveLinkColor = Color.White
            .LinkBehavior = LinkBehavior.SystemDefault
            .LinkColor = Color.Blue
            .TrackVisitedState = True
            .VisitedLinkColor = Color.YellowGreen
        End With
        DataGridView1.Columns.Add(links)
    End Sub
    This doesn't help me do what I want?
    Blake

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???

    Every class has at least two topics dedicated to it in the MSDN library: one an overview of the class and the other a list of members. Had you read the class overview for the DataGridViewLinkColumn class you would have seen this:
    To respond to user link clicks, handle the DataGridView.CellContentClick event. You can also use the DataGridView.CellClick event to respond to clicks anywhere in the cell.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???

    If a user clicks on a file name within a LinkCell....will the appropriate program open the file or does that need to be programmed accordingly?

    Thanks,
    Blake

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???

    will the appropriate program open the file
    You've already said that when you click a link nothing happens.
    does that need to be programmed accordingly
    The documentation I quoted says that you're supposed to handle the CellContentClick event of the grid. Why do you usually handle events? So that you can execute some code when something happens. In this case that means performing the desired action when the user clicks the content in your link cells.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    Hyperactive Member
    Join Date
    Nov 2004
    Posts
    362

    Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???

    you have to pocess the action in event, although you can define a 'LinkCell'. just like in RichText, you can enable LinkText, but you have to process it in LinkClicked event.

    you can use default browser to open the link:
    Try
    System.Diagnostics.Process.Start(e.LinkText)
    Catch ex As Exception
    MsgBox("Can not open " & e.LinkText & " using default browser!", MsgBoxStyle.Information Or MsgBoxStyle.OkOnly)
    End Try

    bear

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???

    Thank you Flying Bear...that's exactly the answer I was looking for. I didn't think my question was that hard to understand. Some people just can't give a straight answer.
    Blake

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???

    Bear,

    To which object does the LinkClicked Event belong to?

    Thanks,
    Blake

  12. #12
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???

    You handle the CellClick event and test e.ColumnIndex to see it it's the link column. If it is, you do as Flying Bear have shown.

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???

    I didn't think my answer was that hard to understand:
    handle the CellContentClick event of the grid
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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