简体   繁体   English

如何使用datagridview c#读取图片路径

[英]How to read picture path with datagridview c#

i wanna ask you something , that i have a data grid that show specific data from my database .我想问你一件事,我有一个数据网格,可以显示我数据库中的特定数据。 this data include a picture box that must show the picture from picture's path that stored in database.The picture path is stored as a string value in column pic in database.But data grid show the all data without showing any picture in the picture box.该数据包括一个图片框,它必须显示数据库中存储的图片路径中的图片。图片路径在数据库中的pic列中存储为字符串值。但数据网格显示所有数据,但不显示图片框中的任何图片。 I want it when i click on data gird cell show me the picture of that row in picture box (reading the picture path from database and show the picture in the picture box) this is my code :当我点击数据网格单元格时,我想要它在图片框中显示该行的图片(从数据库中读取图片路径并在图片框中显示图片)这是我的代码:

private void searchInfo()
{
    con.Open();
    adapter = new OleDbDataAdapter("select * from customers where c_name like'%" + c_name_search.Text + "%'", con);
    adapter.Fill(table);

    res_cid.DataBindings.Add("text", table, "id");
    res_cname.DataBindings.Add("text", table, "c_name");
    pcard_type_res.DataBindings.Add("text", table, "c_pic_type");
    picturebox1.DataBindings.Add("text",table,"pic");
    picturebox1.SizeMode = PictureBoxSizeMode.StretchImage;
    bmb = this.BindingContext[table];
    datagrid.DataSource = table;
     con.Close();
}

thank you ...谢谢你 ...

Maybe if you change the "text" parameter to "Image" or "ImageLocation".也许如果您将“text”参数更改为“Image”或“ImageLocation”。

For example:例如:

picturebox1.DataBindings.Add(new Binding("ImageLocation",table,"yourtablename.yourcolumnname",true));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM