试图找到一种创建支持多个链接的DataGridViewCell的方法,如下所示:
Multiple Links in a GridView Example
我知道这个问题已经被问了一千遍了(我花了整整一天的时间梳理它们),但是请听我说。我希望一个单元格包含多个用逗号分隔的链接。我找到了一种使用LinkLabel做到这一点的方法:
var addresses = new List<string>
{
"http://www.example.com/page1",
"http://www.example.com/page2",
"http://www.example.com/page3",
};
var stringBuilder = new StringBuilder();
var links = new List<LinkLabel.Link>();
foreach (var address in addresses)
{
if (stringBuilder.Length > 0) stringBuilder.Append(", ");
// We cannot add the new LinkLabel.Link to the LinkLabel yet because
// there is no text in the label yet, so the label will complain about
// the link location being out of range. So we'll temporarily store
// the links in a collection and add them later.
links.Add(new LinkLabel.Link(stringBuilder.Length, address.Length, address));
stringBuilder.Append(address);
}
// We must set the text before we add the links.
linkLabel1.Text = stringBuilder.ToString();
foreach (var link in links)
{
linkLabel1.Links.Add(link);
}
linkLabel1.AutoSize = true;
linkLabel1.LinkClicked += (s, e) =>
{
MessageBox.Show((string)e.Link.LinkData);
};
LinkList with Multiple Links Output
我找不到将此LinkList添加到DataGridViewCell的方法。是否可以通过某种方式将此LinkLabel插入到DataGridViewCell中,并且仍然可以正常运行?还是可以通过某种方式使用DataGridViewLinkColumn来获得相同的功能?