【发布时间】:2011-08-17 15:46:33
【问题描述】:
我有两种形式:一种是equipmentfinder,另一种是productdescription。我有一个 datagridview 列 productname 和 productimage 在 equipmentfinder 表单中。
当我单击其中一个列(即)productimage 列时,它将转到另一个工作正常的页面。
我正在制作 WinForms 应用程序。
但我想在 equipmentfinder 表单的另一个图片框中的 datagridview 中的 productimage 列中显示选定的产品图像。
为此,我这样做了:
private void productGridview_Cellclick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == productgridview.Columns["productimage"].Index)
{
ProductDescriptionForm pf = new ProductDescriptionForm();
pf.ShowDialog(this);
}
}
在productdescription 的表格中我已经这样做了:
private void ProductDescriptionForm_Load(object sender, EventArgs e)
{
EquipmentFinder eqipu = new EquipmentFinder();
this.imagepicture.Image = (Image)eqipu.productgridview.SelectedCells.GetType();
}
但我在这一行遇到了错误:
this.imagepicture.Image =(Image)eqipu.productgridview.SelectedCells.GetType();
错误:无法将类型 system.type 转换为 system.drawing.image
【问题讨论】:
-
GetType 为您提供单元格的类型,而不是单元格的内容作为类型。您可能想尝试删除 GetType() 位并将 SelectedCell 转换为图像(或单元格内的项目)
-
怎么做,请您帮忙...
-
@tony 你能帮忙吗...
-
抱歉耽搁了,请参阅下面 James 的回复,它更好地解释了我所说的内容!
标签: c# .net winforms image datagridview