Showing Hyperlink in Winforms Datagrid Control

livehed

New member
Joined
Jan 20, 2006
Messages
2
Programming Experience
Beginner
Hi,
I'm working on a VB.Net Winforms application.
I need to show hyperlink in the Datagrid cell based on some conditions.
Can anyone help me on this please...?

Thanks in advance...!
Regards,
livehed
 
It's not exactly what you want, but I am trying VB 2005 and find it a lot easier to use than 2003. You now have a DataGridViewLinkColumn that is pretty handy, you can't change type at runtime but at least the cursor changes when the cell is empty.

VB.NET:
[SIZE=2][COLOR=#0000ff]
 

Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] GridForm[/SIZE][INDENT][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] GridForm_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load[/SIZE][INDENT][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] DataGridView1
.Rows.Add([/SIZE][SIZE=2][COLOR=#800000]"Billy"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"Mountain View, California"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"http:\\www.microsoft.com"[/COLOR][/SIZE][SIZE=2])
.Rows.Add([/SIZE][SIZE=2][COLOR=#800000]"Steve"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"Cupertino"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"http:\\www.apple.com"[/COLOR][/SIZE][SIZE=2])
.Rows.Add([/SIZE][SIZE=2][COLOR=#800000]"Bob"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"SPM"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE]

[/INDENT][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
 

[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] DataGridView1_CellContentClick([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.DataGridViewCellEventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] DataGridView1.CellContentClick[/SIZE][INDENT][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Row [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = e.RowIndex
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Column [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = e.ColumnIndex[/SIZE]
[SIZE=2][COLOR=#0000ff]     If[/COLOR][SIZE=2] [/SIZE]Row > 0 [COLOR=#0000ff]Then[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]     Dim[/COLOR][/SIZE][SIZE=2] Website [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = DataGridView1.Item(Column, Row).Value
[/SIZE][SIZE=2][COLOR=#0000ff]     If[/COLOR][/SIZE][SIZE=2] Column = 2 [/SIZE][SIZE=2][COLOR=#0000ff]AndAlso[/COLOR][/SIZE][SIZE=2] Website <> [/SIZE][SIZE=2][COLOR=#800000]"" [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]         'Treat you hyperlink
[/COLOR][/SIZE][SIZE=2]         Console.WriteLine(Website)
[/SIZE][SIZE=2][COLOR=#0000ff]     End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End [SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[/COLOR][/SIZE]

[/INDENT][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]

[/INDENT][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]
 
Last edited:
Back
Top