0

I have a DataGridView with the columns added manually, for example:

DataGridViewLinkColumn col = new DataGridViewLinkColumn() { HeaderText = "", DataPropertyName = "PropValue", ReadOnly = true };
        this.dataGridResults.Columns.Add(col);

The datasource is a stored procedure which returns a list with "PropValue" and "PropText" among others.

My problem is that this DataGridViewLinkColumn must show the text from "PropText" and have its value bound to "PropValue". However it seems that DataPropertyName is not that flexible, it only binds to one data type returned from the datsource.

If the problem explanation isn't clear please let me know.

Ideas?

Thank you in advance

Amc_rtty
  • 3,662
  • 11
  • 48
  • 73

2 Answers2

0

You can use 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);

I got it from this link:

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

Community
  • 1
  • 1
Pushpendra
  • 814
  • 1
  • 6
  • 17
0

I ended up using two separate columns, with one invisible that contains the other value i needed. binding both columns from the dataset into th same datagridview column is not possible.

Amc_rtty
  • 3,662
  • 11
  • 48
  • 73