【问题标题】:dataGridView image column link to filedataGridView 图像列链接到文件
【发布时间】:2015-05-25 01:24:07
【问题描述】:
我正在处理 dataGridView 上的图像列:
如附图所示,当我点击“浏览”时,我可以从对话框窗口中选择一个文件。
我想要什么...
是使“文件”图像列上的图像链接到所选文件(以在用户单击图像时打开文件)。
我不知道如何做到这一点。谁能给我一个方向?
【问题讨论】:
标签:
c#
image
file
user-interface
datagridview
【解决方案1】:
首先您可以创建自己的类并放入该类的文件路径属性
我已经创建了示例:
public class MyClass
{
public string Name{get;set;}
public string FilePath{ get; set; }// Here i put The path and it will not appear in the Grid will just show the first item
}
在 DataGrid 中有一个名为 SelectionChanged 的事件您可以在其中添加此代码
if (DG.CurrentColumn.Header.ToString() == "Name")
Process.Start((DG.SelectedItem as MyClass).FilePath);
当我选择项目时,它将打开您可以放置的文件夹,而不是(“名称”)您的列名称(“浏览”)