Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1846
  • Last Modified:

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!
0
DavidGreenfield
Asked:
DavidGreenfield
  • 3
  • 3
  • 2
1 Solution
 
newyuppieCommented:
the DataGridView allows you to do this already i believe. just right click on the datagridview, edit columns, and set the COlumnType to DataGridViewLinkColumn
0
 
Kinger247Commented:
Set the column type to DataGridViewLinkColumn (for each column).
0
 
newyuppieCommented:
hi kinger! only 25 more points and you get Master! congrats
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
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!
0
 
newyuppieCommented:
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

0
 
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!
0
 
Kinger247Commented:
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
        Next
0
 
DavidGreenfieldAuthor Commented:
Kinga, that works perfectly.  Thank you very much indeed!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now