|
-
Jun 21st, 2007, 03:31 PM
#1
Thread Starter
PowerPoster
Creating a link for a DGV?
I have a DGV in which one of the columns is a DB Table field called fileName. It's values look like this: "Invoice.txt" (minus the quotes).
I wish to be able to make it a link...where the user can click on it and the document will open according to it's association if one is established. How can I get the fileName field to load in the grid as a HyperLink or Link?
Thanks,
Last edited by blakemckenna; Jun 21st, 2007 at 03:50 PM.
Blake
-
Jun 21st, 2007, 04:00 PM
#2
New Member
Re: Creating a link for a DGV?
in your data grid view, make the fileName column of type DataGridViewLinkColumn instead of the default DataGridViewTextBoxColumn. This will underline the text and change the cursor when you hover over the cell.
Then to open the file in the link, in the datagridviews cellClick event:
VB Code:
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim linkColumnIndex As Integer = 3 'or whatever index your column is
If e.ColumnIndex = linkColumnIndex Then
System.Diagnostics.Process.Start(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)
End If
End Sub
(this is assuming that the full path is in cell being clicked. If it is not, you will have to append the folder path to the the cell value.)
-
Jun 21st, 2007, 08:05 PM
#3
Re: Creating a link for a DGV?
You should handle the CellContentClick event rather than the CellClick. Otherwise you will be acting even if the link wasn't activated.
Note also that you must add this column at design time if your grid is generating the columns for you. Otherwise you will just get the text box column as normal. You set the column's DataPropertyName to tell it which column of the data source to bind to.
-
Jun 22nd, 2007, 09:28 AM
#4
Thread Starter
PowerPoster
Re: Creating a link for a DGV?
JMC,
This grid is created as a result of a DB Table. In this case there are only 3 columns. In design view, the grid is blank but I bind the grid to a DB Table. Once I bind the grid to the Table, I have a sub that formats the headers. Could I add the code there to create the linked column?
-
Jun 22nd, 2007, 08:27 PM
#5
Re: Creating a link for a DGV?
 Originally Posted by blakemckenna
JMC,
This grid is created as a result of a DB Table. In this case there are only 3 columns. In design view, the grid is blank but I bind the grid to a DB Table. Once I bind the grid to the Table, I have a sub that formats the headers. Could I add the code there to create the linked column?
I specifically addressed that issue in my previous post.
 Originally Posted by jmcilhinney
Note also that you must add this column at design time if your grid is generating the columns for you. Otherwise you will just get the text box column as normal. You set the column's DataPropertyName to tell it which column of the data source to bind to.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|