将具有图片文件名的列绑定到WinForms中的GridViewImageColumn [英] bind a column which has filename of picture to GridViewImageColumn in WinForms

查看:91
本文介绍了将具有图片文件名的列绑定到WinForms中的GridViewImageColumn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
我的表中有3个字段:( name,family和PictureFileName)

PictureFileName字段具有图片文件的名称和路径。因为我不在数据库中恢复图像,但我在数据库中恢复文件的名称并将图片保存到硬盘中的路径。

现在我想将搜索结果发送到RadGridView。如何在姓名和家人之后在RadGridView的唱片中显示每个人的照片?





非常感谢

Hi There are 3 fields in my table : (name, family and PictureFileName)
PictureFileName field has the name and path of file of picture. Because I don’t restore image in database but I restore name of file in Database and save picture to a path in hard disk.
Now I wants to send result of search to a RadGridView . how can I show picture of every person in a record in RadGridView after name and family?


Thanks very much

推荐答案

你可以添加一个DataGridViewImageColumn并将图像源或路径设置为数据库中保存的路径。这样就可以了。



you can add a DataGridViewImageColumn and set the image source or path as the path saved in your database Like this

dataGridView1[yourColumn, yourRow].Value = Image.FromFile(path); 





或者您可以将DataGridViewLinkCell列添加到您的网格

然后在CellContentClick中或CellClick事件检查它是否为然后DataGridViewLinkCell打开这样的文件





Or you can add DataGridViewLinkCell Column to your grid
then in CellContentClick Or CellClick Event check if its the DataGridViewLinkCell then open the file like this

private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    if (e.RowIndex < 0 || currentMouseOverRow < 0)
        return;

    int ColpthIndx = dataGridView1.Columns["colATTCH_FILE_NAME"].Index;
    if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] is DataGridViewLinkCell)
    {
        if (e.ColumnIndex == ColpthIndx)Process.Start(dataGridView1.Rows[e.RowIndex].Cells["colATTCH_FILE_NAME"].Value as string);
    }

}


这篇关于将具有图片文件名的列绑定到WinForms中的GridViewImageColumn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆