Avatar of DJ P
DJ PFlag for United States of America

asked on 

Hyper Links In Dataview Grid

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.
Visual Basic.NETDatabasesMicrosoft Access

Avatar of undefined
Last Comment
Scott McDaniel (EE MVE )
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of DJ P
DJ P
Flag of United States of America image

ASKER

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.
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

Open in new window


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
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo