如何在不使用 cutomunboundcolumn 事件的情况下从图像路径显示 gridview 单元格中的图像?
我有一个网格视图,我想在其中显示路径存储在数据库中的图像。我已经尝试过这段代码,但它在所有行中只重复一张图片。谁能帮我解决这个问题?我不想使用 customunboundcolumn 事件。我的代码如下所示
SqlCommand cmd = new SqlCommand("select * from picture", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds);
gridControl1.DataSource = ds.Tables[0];
DevExpress.XtraGrid.Columns.GridColumn image = new DevExpress.XtraGrid.Columns.GridColumn();
gridView1.Columns.Add(image);
image.Caption = "Image";
image.Name = "img";
image.FieldName = "img";
image.Visible = true;
image.VisibleIndex = 3;
int row = ds.Tables[0].Rows.Count;
DevExpress.XtraGrid.Views.Base.ColumnView cgv = (DevExpress.XtraGrid.Views.Base.ColumnView)gridView1;
DevExpress.XtraEditors.Repository.RepositoryItemImageEdit rpic = new DevExpress.XtraEditors.Repository.RepositoryItemImageEdit();
rpic.NullText = "No Image";
rpic.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom;
DevExpress.Utils.ImageCollection images = new DevExpress.Utils.ImageCollection();
for (int i = 0; i < row; i++)
{
string imgpath = ds.Tables[0].Rows[i]["fpath"].ToString();
images.Images.Add(Image.FromFile(imgpath));
rpic.Images = images;
gridView1.Columns["img"].ColumnEdit=rpic;
gridView1.SetRowCellValue(i,"Image",rpic);
gridView1.SelectRow(i);
MessageBox.Show(gridView1.FocusedRowHandle.ToString());
// gridView1.SetFocusedRowCellValue("Image",gridView1.Columns["img"].ColumnEdit= rpic);
}
gridView1.BestFitColumns();
I have a grid view in which I want to show images whose paths are stored in a database. I have tried this code but it repeats only one picture in all rows. Can anyone help me to solve this problem? I don't want to use the customunboundcolumn event. My code is shown below
SqlCommand cmd = new SqlCommand("select * from picture", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds);
gridControl1.DataSource = ds.Tables[0];
DevExpress.XtraGrid.Columns.GridColumn image = new DevExpress.XtraGrid.Columns.GridColumn();
gridView1.Columns.Add(image);
image.Caption = "Image";
image.Name = "img";
image.FieldName = "img";
image.Visible = true;
image.VisibleIndex = 3;
int row = ds.Tables[0].Rows.Count;
DevExpress.XtraGrid.Views.Base.ColumnView cgv = (DevExpress.XtraGrid.Views.Base.ColumnView)gridView1;
DevExpress.XtraEditors.Repository.RepositoryItemImageEdit rpic = new DevExpress.XtraEditors.Repository.RepositoryItemImageEdit();
rpic.NullText = "No Image";
rpic.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom;
DevExpress.Utils.ImageCollection images = new DevExpress.Utils.ImageCollection();
for (int i = 0; i < row; i++)
{
string imgpath = ds.Tables[0].Rows[i]["fpath"].ToString();
images.Images.Add(Image.FromFile(imgpath));
rpic.Images = images;
gridView1.Columns["img"].ColumnEdit=rpic;
gridView1.SetRowCellValue(i,"Image",rpic);
gridView1.SelectRow(i);
MessageBox.Show(gridView1.FocusedRowHandle.ToString());
// gridView1.SetFocusedRowCellValue("Image",gridView1.Columns["img"].ColumnEdit= rpic);
}
gridView1.BestFitColumns();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将 ColumnEdit 设为
RepositoryItemPictureEdit
然后
You need to make your ColumnEdit as a
RepositoryItemPictureEdit
Then
您必须使用 DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit。
You have to use DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit.