kik
kik

Reputation: 247

How to add DataGridViewLinkColumn property to dynamically generated columns in DataGridView?

Developing In: c# winforms without any Database Connections

Description: In my DataGridView, columns were dynamically generated.At some point some of the columns need to be DataGridViewLinkColumn property. I was tried in many ways but didn't achive this.

I hope someone from here would help me :)

Thanks In Advance.

Upvotes: 3

Views: 8094

Answers (2)

hawbsl
hawbsl

Reputation: 16003

You will need to switch off AutoGenerateColumns, then generate each column yourself.

Setup the normal columns as type DataGridViewTextBoxColumn, then for the columns which need to be Linked columns set them up as type DataGridViewLinkColumn.

Upvotes: 1

Jacob Seleznev
Jacob Seleznev

Reputation: 8131

Try this:

       DataGridViewLinkColumn links = new DataGridViewLinkColumn();

        links.HeaderText = "Hello";
        links.UseColumnTextForLinkValue = true;
        links.Text="http://microsoft.com";
        links.ActiveLinkColor = Color.White;
        links.LinkBehavior = LinkBehavior.SystemDefault;
        links.LinkColor = Color.Blue;
        links.TrackVisitedState = true;
        links.VisitedLinkColor = Color.YellowGreen;

        dataGridView.Columns.Add(links);

Upvotes: 6

Related Questions