-1

enter image description here

Clicking on the link does't do anything, it basically wont open the link

  • It won't open the link by itself. You need to handle some event, get the link, and open it. Read [DataGridView.CellContentClick](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.datagridview.cellcontentclick?view=netframework-4.8) –  Apr 19 '20 at 07:43
  • Please express your question more precisely. – Mehrdad Mirreza Apr 19 '20 at 12:11

1 Answers1

1

As JQSOFT mentioned, you need to subscribe to the event CellContentClick to open the link.

Please refer to the demo.

private void Form1_Load(object sender, EventArgs e)
{
    // Add link column
    DataGridViewLinkColumn links = new DataGridViewLinkColumn();
    links.HeaderText = "Link";
    links.LinkBehavior = LinkBehavior.SystemDefault;
    dataGridView1.Columns.Add(links);

    // Add new link data
    DataGridViewRow dr = new DataGridViewRow();
    dr.CreateCells(dataGridView1);
    dr.Cells[0].Value = "www.microsoft.com";
    dataGridView1.Rows.Add(dr);
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    if (e.ColumnIndex == 0)
    {
        var row = dataGridView1.Rows[e.RowIndex];
        if (row.Cells[0].Value == null) return;
        var url = row.Cells[0].Value.ToString();
        System.Diagnostics.Process.Start(url);
    }
}
大陸北方網友
  • 3,696
  • 3
  • 12
  • 37