简体   繁体   English

DataGridViewLinkColumn 不响应点击

[英]DataGridViewLinkColumn does not respond to clicks

enter image description here在此处输入图像描述

Clicking on the link does't do anything, it basically wont open the link点击链接不做任何事情,它基本上不会打开链接

As JQSOFT mentioned, you need to subscribe to the event CellContentClick to open the link.正如 JQSOFT 所提到的,您需要订阅事件CellContentClick才能打开链接。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM