Link to home
Start Free TrialLog in
Avatar of Steve5140
Steve5140

asked on

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 !!
Avatar of Steve5140
Steve5140

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Naman Goel
Naman Goel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 !!
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.