How to add a DataGridViewLinkColumn property to dynamically created columns in a DataGridView?

Development in: c# winforms without any database connections

Description: In my DataGridView, the columns were dynamically generated. At some point, some of the columns should be the DataGridViewLinkColumn property. I was tried differently, but did not achieve this.

I hope someone here helps me :)

Thanks in advance.

+3
source share
2 answers

You need to disable AutoGenerateColumnsand then create each column yourself.

Set the normal columns as a type DataGridViewTextBoxColumn, then for the columns that should be Linked columns set them as a type DataGridViewLinkColumn.

+1

:

       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);
+6

All Articles