Datagridview - Linklabel

Hi there

Is it possible to create a column in a datagridview where all the cells are shown as link labels?  If so how do I got about this

many thanks!
Who is Participating?
Kinger247Connect With a Mentor Commented:
I know of no otherway of changing the column type after you have loaded it with data.
So what I would do is loop through each cell and

1. Copy its contents locally.
2. Manually change its type.
3. Replace its contents.

Like this:

        Dim ColumnToChange As Integer = 1
        Dim CurrentValue As String

        For i As Integer = 0 To DataGridView1.Rows.Count - 1
            CurrentValue = DataGridView1(ColumnToChange, i).Value
            DataGridView1(ColumnToChange, i) = New DataGridViewLinkCell
            DataGridView1(ColumnToChange, i).Value = CurrentValue
the DataGridView allows you to do this already i believe. just right click on the datagridview, edit columns, and set the COlumnType to DataGridViewLinkColumn
Set the column type to DataGridViewLinkColumn (for each column).
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

hi kinger! only 25 more points and you get Master! congrats
DavidGreenfieldAuthor Commented:
How can I use the datagridviewlinkcolumn with exisitng data?

My data is being loaded form a data table,  and its on one of the columns I want turn into a link label.  I can only find information on adding a column in, not actually using the data thats already there in the table.

Can I not do this?

thanks for your help so far!
when you are in the designer, right click and edit columns in the datagridview. select the column you want to turn into a link label, and navigate the property sheet of that column until you find ColumnType. change that to DataGridViewLinkColumn.

unless you are automatically generating the columns, in which case you must do it by code using something like this:

Dim column As DataGridViewColumn = dataGridView.Columns("Links")
        column.ColumnType = DataGridViewLinkColumn

DavidGreenfieldAuthor Commented:
Hi newyuppie

I am automatically generating the columns,

but the code you gave me does not work.  It says columntype is not a member of datagridviewcolumn.  I have celltype option - but this then errors on datagridviewlinkcolumn saying its not a type and cannot be used as an expression.

thanks foryour help so far!
DavidGreenfieldAuthor Commented:
Kinga, that works perfectly.  Thank you very much indeed!
All Courses

From novice to tech pro — start learning today.