DataGridViewLinkColumn does not respond to clicks

297 Views Asked by At

enter image description here

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

1

There are 1 best solutions below

0
On

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);
    }
}