DataGridView列中的超链接

时间:2011-03-03 11:14:35

标签: c# winforms

  

可能重复:
  how to give hyperlink to Image Column in Datagridview

我可以在DataGridView的包含Image的列中提供超链接吗?单击图像后,指定的url应该打开吗?

1 个答案:

答案 0 :(得分:1)

您可以使用Dictionary<Image,string>将链接映射到图像,然后在图像单元格上处理点击事件

Dictionary<Image,string> UrlDicationary = new Dictionary<Image, string>();
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
     if(e.ColumnIndex == your_image_column_index)
     {
         Image image = dataGridView1[e.ColumnIndex, e.RowIndex].Value as Image;
         if(image != null)
         {
               string url;
               if(UrlDicationary.TryGetValue(image, out url))
               {
                    Process.Start(url);
               }
         }
     }
}

您需要先填写字典

相关问题