We help IT Professionals succeed at work.

Hyper Links In Dataview Grid

27 Views
Last Modified: 2020-06-05
Hello experts. I created a form in vb.net (desktop application). I am playing around with a datagridview for the first or second time (newbie). The datagrid connects to a ms access database. The name of the table is called Master. In the table I have a field called File with a data type of hyper link. What I would like is the user click on the hyper link and have it open the appropriate pdf file. For example the pdf file for testing purposes is setup and located at c:\test\201\201.PDF.

In my access table in the field it shows up as the following file:///c:\test\201\201.PDF.  However, when I run my application it shows up in the grid as follows: #file:///c:\Test\201\201.PDF and is grayed out.

My question is how do I get it to just show up with the file name like 201.PDF and have the user click on the hyper link to open the file? Keep in mind I'm fairly new so the simpler the better.
Comment
Watch Question

Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks Scott,

I looked at the article and created a test form using the articles code and have a couple of questions. First one is when I copy and paste the code in the article on my test form everything populates in the grid. The links supplied in the grid do not open the page when selecting. I also changed the links just in case to google and the page still does not open. Am I missing something? Also, and here is where I am not great at programming, assuming the links worked how do I tie those to the fields in my access db? The example shows hard coded results with the same link populating the same records in the grid. Hope that makes sense.
Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
You'd have to handle the CellContentClick event to do anything with the user click.

 Private Sub YourDGV_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles YOURDATAGRIDVIEW.CellContentClick      

If e.ColumnName="NameOfYourLinkColumn" Then
   Process.Start(YourDataGridView.Rows(e.RowHandle).Cells(e.Column).Value
End If
End Sub

Something like that. I haven't used the DataGridView in a while, but I believe you're provided with the RowHandle and Column values from the DataGridViewCellEventArgs.
You'd obviously have to use the name of your DataGridView and Column where indicated

https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.datagridview.cellcontentclick?view=netcore-3.1
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.