dataGridView图像列链接到文件

时间:2015-03-21 19:02:15

标签: c# image file user-interface datagridview

我正在使用dataGridView上的image列:

如附图所示,当我点击“浏览”时,我可以从对话框窗口中选择一个文件。

我想要的......

是将'Files'图像列上的图像链接到所选文件(以便在用户点击图像时打开文件)。

我不知道如何实现这一目标。有人能指点我吗? enter image description here

1 个答案:

答案 0 :(得分:0)

首先,您可以创建自己的类,并将此类属于文件路径 我创造了一个例子:

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

当我选择项目时,它将打开您可以放置​​的文件夹而不是(“名称”)您的列名称(“Brows”)