DataGridView和PictureBox [英] DataGridView and PictureBox
问题描述
您好,我正在Microsoft Visual Studios 2008中的c#.net中开发一个图片查看器窗口应用程序.我被困在如何从gridview中获取选定的缩略图以显示在Picturebox中的问题上.
这是我使用的代码:
Hi, I am developing a picture viewer window application in c# .net in Microsoft visual studios 2008. I am stuck on how to get a selected thumbnail image from the gridview to be displayed in the Picturebox.
Here is the code i used:
private void dataViewImages_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
string pic = dataViewImages.SelectedRows[0].ToString();
pictureBox.Image = Image.FromFile(pic);
tsbSave.Enabled = true;
tsbRotate.Enabled = true;
tsbCCRotate.Enabled = true;
}
我收到的错误消息是:
索引超出范围.必须为非负数并且小于集合的大小.
参数名称:索引.
-----------------------------
我知道它将与... SelectedRows [0]有关,但与此同时,我也不知道如何解决它.
The error message i am getting is:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index.
-----------------------------
i know it will have to do with the ...SelectedRows[0] but at the same time i don''t know how to fix it.
推荐答案
检查是否有选择.在使用数组之前,请检查是否有选定的行.
Check if there is any selected or not. Place a check that if there is any selected row or not before you use the array.
这篇关于DataGridView和PictureBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!