将图像添加到网格

编程入门 行业动态 更新时间:2024-10-11 03:23:05
本文介绍了将图像添加到网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好,我想在一个列中添加图像,每行添加10个图像,并且没有图像取决于从数据库中获取的记录数

Hello I am trying to add images in a col, 10 images in each row and no of images depends on no of records fetched from database

List<Image> lstImage = new List<Image>(); for (int i = 0; (i < recLeft) ; i++) { Image img = Image.FromFile( <complete path="">"tmp.jpg"); Image newImg = img.GetThumbnailImage(_imageSize, _imageSize, null, IntPtr.Zero); lstImage.Add(newImg); } for (int row = 0; row < numRows; row++) { DataGridViewRow dRow = new DataGridViewRow(); recLeft = numRec - (numColumnsForWidth * row); for (int col = 0; (col < recLeft) && (col < numColumnsForWidth); col++) { this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.Rows[row].Cells[col].Value= lstImage[0]; } dataGridView1.Rows.Add(); }

我在遇到错误

I am getting error at

dataGridView1.Rows[row].Cells[col].Value= lstImage[0];

"index out of range" even if i substitute row and col in above line with 0, which means trying to add atleast one image in 1st col and 1st ro then again error is same.

如果有人可以对此进行说明. 谢谢

If anybody can put light on this. Thanks

推荐答案

即使我用0代替上一行中的row和col,这意味着尝试在第一个col和第一个ro中添加至少一个图像,然后再次错误是相同的 根据您的代码,您似乎在运行时将行添加到网格中.现在,除非将行添加到网格中,否则您无法访问该行进行任何值分配. 最后一步将行添加到网格,而您尝试在添加之前访问同一行(尝试分配图像!) 更正您的逻辑.首先添加该行,然后添加图像. even if i substitute row and col in above line with 0, which means trying to add atleast one image in 1st col and 1st ro then again error is same Based on your code, it looks like you are adding rows to grid at runtime. Now, unless until row is already added to the grid, you cannot access the row for any value assignment. Your final step adds the row to grid whereas you try to access the same row before this addition (where you are trying to assign the image!) Correct your logic. First add the row and then add the image.

更多推荐

将图像添加到网格

本文发布于:2023-08-06 11:29:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1311980.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   图像

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!