当前位置:首页 > 软件设计 > 正文

GridControl的一列中显示图片

GridControl的一列中显示图片

设置标题FieldName设为 PhotoColumnEdit设为RepositoryItemPictureEdit类UnboundType设为 UnboundColu...

设置标题FieldName设为 Photo

ColumnEdit设为RepositoryItemPictureEdit类

UnboundType设为 UnboundColumnType.Object

image.png

image.png

代码

private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)

        {

            if (e.Column.FieldName == "Photo" && e.IsGetData)

            {

                //RefImage是存储图片路径的那一列

                string filePath = (string)((DataRowView)e.Row)["图片地址"];

                Image img = null;

                try

                {

                    //判断图片路径是否为网络路径

                    if (PublicGetConnect.UrlDiscern(filePath)==true)

                    {

                        //文件是否存在

                        if (PublicGetConnect.RemoteFileExists(filePath))

                        {

                            //读取文件

                            using (WebClient wc = new WebClient())

                            {

                                img = new Bitmap(wc.OpenRead(filePath));

                            }

                        }

                    }

                    // 判断本地文件是否存在

                    else if (PublicGetConnect.LocalFileExists(filePath))

                    {

                        //加载本地图片

                        img = Image.FromFile(filePath);

                    }

                    //pictureEdit列绑定图片

                    e.Value = img;

                }

                catch (Exception ex)

                {

                    MessageBox.Show(ex.ToString());

                }

            }

        }


发表评论

最新文章

取消
扫码支持 支付码