datagridview 点击一行数据 显示图片在PictureBox控件中。如何实现。用C#!!
privatevoiddataGridView1_CellClick(objectsender,DataGridViewCellEventArgse){stringpat...
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
string path=dataGridView1.Rows[dataGridView1.CurrentRow.Index ].Cells["path"].Value.ToString() ;
}
private void dataGridview1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGridview1.Columns[e.ColumnIndex].Name.Equals("Image"))
{
string path = e.Value.ToString();
e.Value = GetImage(path);
}
}
public System.Drawing.Image GetImage(string path)
{
System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open);
System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
fs.Close();
return result;
}
有什么问题吗? 展开
{
string path=dataGridView1.Rows[dataGridView1.CurrentRow.Index ].Cells["path"].Value.ToString() ;
}
private void dataGridview1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGridview1.Columns[e.ColumnIndex].Name.Equals("Image"))
{
string path = e.Value.ToString();
e.Value = GetImage(path);
}
}
public System.Drawing.Image GetImage(string path)
{
System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open);
System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
fs.Close();
return result;
}
有什么问题吗? 展开
2013-07-29
展开全部
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
string path=dataGridView1.Rows[dataGridView1.CurrentRow.Index ].Cells["path"].Value.ToString() ;
System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open);
图片控件.Image= System.Drawing.Image.FromStream(fs);
fs.Close();
}若希望程序更健壮,可以给图片读取套上try
{
string path=dataGridView1.Rows[dataGridView1.CurrentRow.Index ].Cells["path"].Value.ToString() ;
System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open);
图片控件.Image= System.Drawing.Image.FromStream(fs);
fs.Close();
}若希望程序更健壮,可以给图片读取套上try
2013-07-29
展开全部
楼主,你好有些控件是不符合硬盘的,所以才会出现上面的情况,建议你找一个电脑程序者、帮你解决问题。如果有帮到你的、请采纳为答案、谢谢、QQ1076921218
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询