从gridview选择图像 [英] Selecting an image from a gridview

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

问题描述

你好,
我有一个网格视图,其中显示了从文件夹中打开的图像.一旦我单击了网格视图中的图像,它将显示在我的图片框中以放大.但是,当我在gridview中单击不同的图像时,它会通过一条错误消息指出我的数字为负数,需要更正.这是在gridview中选择图像后我拥有的代码:

Hello,
I have a grid view which displays images opened from a folder. Once i click on an image from the gridview it shows in my picturebox to enlarge. But when i click on a different image in the gridview it throughs an error stating that i have a negative number and needs to be corrected. Here is the code i have once an image is selected in the gridview:

private void dataViewImages_CellContentClick(object sender, DataGridViewCellEventArgs e)
{           
      string pic = dataViewImages.SelectedCells[e.RowIndex].ToString();
      pic = this._files[e.RowIndex];
      this.Text = pic;
      MessageBox.Show(pic);
      pictureBox.Image = Image.FromFile(pic);
      tsbSave.Enabled = true;
      tsbRotate.Enabled = true;
      tsbCCRotate.Enabled = true;
      saveToolStripMenuItem1.Enabled = true;
      saveToolStripMenuItem.Enabled = true;
}

推荐答案

1.您没有在任何地方使用numImagesRequired.为什么需要它?
2.您能通过以下几行发现问题吗?

1. You are not using numImagesRequired anywhere. Why do you need it?
2. Can you spot the problem with these lines:

string pic = dataViewImages.SelectedCells[index].ToString();
                pic = this._files[index];



3.为什么需要那个for循环?

我建议有一个隐藏的列,在每行中显示图像的路径.然后,您可以使用以下代码:



3. Why do need that for loop?

I would suggest to have a hidden column with path of the image displayed in each row. Then you can use following:

pic.Image = Image.FromFile(dataGridView.CurrentRow.Cells["hidden column index here"].Value.ToString());


[ ^ ]应该会有所帮助.

如果您不熟悉该技术,那么首先需要的是耐心.人们需要时间来熟悉和理解与此相关的任何技术或任何事物.
This[^] should help.

If you are not familiar with the technology, first thing you need is patience. One needs time to get familiar and understand any technology or anything for that matter.


您能为此提供更多帮助吗?我对Windows窗体和数据网格不是很熟悉,我真的很困惑.我试图使该列隐藏,但随后它将返回未找到的错误列.
Can you help me some more with this? I am not very familiar with windows forms and datagrids and i am getting really confused. i tried to make the column hidden but then it would return an error column not found.


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

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