1

I'm loading a DataSet into a DataGridView. The data is a hyperlink to a file on the local network but I can't get the link to actually launch the file. Do I have to go into the clickevent and actually launch it from there? Or is there a property I can set on the DataGridViewLinkCell to do it without the fuss?

Thanks, code is below.

'dgMain is the DataGridView
dgMain.DataSource = dataSet1.Tables(0)

'Just an example, will format entire column when I'm done
dgMain(10, 1) = New DataGridViewLinkCell

If I did go clickevent route I think it would be something like this but it doesn't work very well but I haven't tried much yet:

Private Sub dgMain_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgMain.CellContentClick
    If e.RowIndex = -1 Then
        Exit Sub
    End If

    If dgMain.Rows(e.RowIndex).Cells(e.ColumnIndex) Is DataGridViewLinkCell Then
        Process.Start(dgMain.Rows(e.RowIndex).Cells(e.ColumnIndex).ToString)
    End If
End Sub
tmwoods
  • 2,353
  • 7
  • 28
  • 55

1 Answers1

1

Yes you need to handle the click event and launch the URL in code (Process.Start)

SSS
  • 4,807
  • 1
  • 23
  • 44
  • 1
    Wow. Really?. So what's the point of having `DataGridViewLinkCell` in the first place?! Is it just make it blue and underlined? Because obviously I could call `Process.Start` from the click event of **any** cell type. – John Henckel Jul 15 '16 at 17:22
  • 1
    Yes, it is just to have the blue color and underline for the contents, that then changes colour after it is clicked :-P On the plus side, you can do anything you want after the click - load a new form, update a WebBrowser control, etc. – SSS Jul 18 '16 at 01:07