• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 980
  • Last Modified:

Need to display folder location as a hyperlink in a data grid view (Windows app)

Hi Experts,

I have populated a datagridview by binding it to a dataview created from an SQL query at run time.

One of the fields is titled "File Folder" and shows a folder location on our server.  I would like to display this column as a hyperlink so that users can simply click it to open explorer and open the folder.

Here is my code so far:

Dim cmd As New SqlClient.SqlCommand(SqlLine$, myConnection)
cmd.CommandTimeout = 120
da.SelectCommand = cmd
DS = New DataSet
da.Fill(DS, "MyTable")
cmd.Connection.Close()
dv = New DataView(DS.Tables("MyTable"))
DGV1.DataSource = dv


Dim links As New DataGridViewLinkColumn()
With links
            .Name = "File Folder"
            .UseColumnTextForLinkValue = True
            .HeaderText = "File Folder2"
            .DataPropertyName = DGV1.Columns("File Folder").DataPropertyName.ToString
            .ActiveLinkColor = Color.White
            .LinkBehavior = LinkBehavior.SystemDefault
            .LinkColor = Color.Blue
            .TrackVisitedState = True
            .VisitedLinkColor = Color.YellowGreen
End With
DGV1.Columns.Add(links)

Open in new window


This code creates a column on my datagridview titled "File Folder2", but the cells are blank.

What am I missing ?

Thanks for your help !!
0
Steve5140
Asked:
Steve5140
  • 2
  • 2
1 Solution
 
Steve5140Author Commented:
Well, I changed .UseColumnTextForLinkValue =   from "True" to "False" and now the hyperlink displays.

I don't understand that, but for now I will accept it.

Next problem is that clicking on the link doesn't do anything.
0
 
Naman GoelCommented:
Implement CellContentClick event

Private Sub DGV1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)
      If TypeOf DGV1.Columns(e.ColumnIndex) Is DataGridViewLinkColumn Then
            Dim folderName As String = DGV1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString()

            Process.Start(String.Format("{0}", folderName))
      End If
End Sub
0
 
Steve5140Author Commented:
OK, that seems to work well.  I changed it slightly to:

If DGV1.Columns(e.ColumnIndex).HeaderText.ToString = "File Folder" Then
            System.Diagnostics.Process........
End If

Open in new window


Just in case I add a second DataGridViewLinkColumn someday in the future.

Can you explain why setting .UseColumnTextForLinkValue to false made the text appear in the cell ?  That just doesn't make sense to me ?

I will happily award the points to you for your answer !!
0
 
Naman GoelCommented:
I never tried this property so it was never set for me and so it was always taking default value for me.
 But it seems that if you make this property true text will be treated as undelink URL for that Hyperlink.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now