日期:2014-05-18  浏览次数:20829 次

C# winform 关于datagridview显示图片的问题
datagridview绑定了数据表friends,数据表里面有“image”列,保存的是图片的绝对路径,我想在datagridview将这些路径显示成图片,该怎么做呢?

------解决方案--------------------
Image.FromFile("文件路径");
------解决方案--------------------
http://topic.csdn.net/t/20060217/21/4562504.html
参照此贴
------解决方案--------------------
http://zhangjiankun880.blog.163.com/blog/static/135540320108276441954/
------解决方案--------------------
C# code

//绑定到DataGridView
        private void BindDategridview()
        {
            dataGridView1.Rows.Clear();
            dataGridView1.DataSource = null;
            //dataGridView1.Rows.Add(5);  
            //DataSet ds = Bll.GetList("Cus_Id='" + cmbsgbw.Text + "'");
            DataSet ds = Bll.GetList("Cus_Id='" + Detail.cuid + "'");
            if (ds.Tables[0].Rows.Count > 0)
            {
                dataGridView1.Rows.Add(ds.Tables[0].Rows.Count);
                string[] str = new string[23];
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    for (int k = 0; k < str.Length; k++)
                    {
                        str[k] = ds.Tables[0].Rows[i].ItemArray[k].ToString();
                        //if (str[k] == "0")
                        //    str[k] = false.ToString();
                        //else if (str[k] == "1")
                        //    str[k] = true.ToString();
                        string s = Class_Path.position + "\\ysimage\\" + ds.Tables[0].Rows[i]["XZ_bianhao"].ToString() + ".jpg";
                        str[5] = s;
                    }
                    //for (int p = 0; p < dataGridView1.Rows.Count; p++)
                    //{
                    for (int q = 0; q < dataGridView1.Columns.Count; q++)
                    {
                        if (q == 5)
                            dataGridView1.Rows[i].Cells[5].Value = Image.FromFile(str[q]);
                        else
                            dataGridView1.Rows[i].Cells[q].Value = str[q];
                    }

                    //} 

                }
            }

------解决方案--------------------
datagridview中图片那一列格式设置为DataGridViewImageColumn 加载数据的时候,图片那一列把读出来的路径赋值给那一列 Image.FromFile(图片路径)
------解决方案--------------------
http://social.microsoft.com/Forums/zh-CN/2212/thread/ffd27d9b-2a0b-4893-8896-1e7a594baea5

http://hi.baidu.com/%C8%ED%BC%FE%CD%F8%C2%E7%B4%BF%BC%BC%CA%F5/blog/item/083466ed53d4d12427979161.html

http://wenku.baidu.com/view/494d880d844769eae009eda5.html