将图像添加到网格 [英] adding images to grid

查看:105
本文介绍了将图像添加到网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想在一个列中添加图像,每行添加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.


这篇关于将图像添加到网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆