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

问题描述

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

推荐答案


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

08-04 08:04
查看更多