datagridview中只要第3行到第8行的列显示图片。怎么做?我用DataGridViewImageColumn这个,会使得一整列都显示图片。
解决方案 »
- C#导出Excel时按类型分Sheet
- VS 中的单元测试怎么玩?
- datagridview怎么直接打印啊
- ××××求救××××IE到底提供了多少COM服务
- [星级问题]外键之XML->DataSet,如何读取?
- 【折腾了我几天的问题】 用WebRequest采用多线程抓取网页时,出现"基础链接已关闭"的错误,大家帮分析一下!!!!!!!!!!
- 我在c#调试模式中出现的问题提示“没有可用于当前位置的源代码”
- 网络游戏公司急招网站开发人员!!!
- WinForm问题!!!急!!!
- (急)当我打开一个EXCEL文件老是出现重载Open未获取“1”参数
- 怎么将html标签转换为服务器控件
- 谁给推荐数据结构 和 算法方面的书
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if ((e.RowIndex < 2 || e.RowIndex > 7) &&
e.ColumnIndex == 显示图片的列索引)
{
e.Value = null;
}
}
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.RowIndex > 2 && e.RowIndex < 7 &&
e.ColumnIndex == 显示图片的列索引)
{
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; }
DataTable dt = new DataTable();
dt.Columns.Add("1");
dt.Columns.Add("2"); DataRow dr=dt.NewRow();
dr["1"] = "11";
dr["2"] = @"C:\Documents and Settings\10528\桌面\12\DataGridDemo2\Resources\Image2.bmp";
dt.Rows.Add(dr); dataGridView2.Rows.Add(10);DataGridViewImageColumn imagecolum = new DataGridViewImageColumn();
imagecolum.HeaderText = "图片列"; DataGridViewImageCell imagecell = new DataGridViewImageCell();
dataGridView2.Columns.Insert(1, imagecolum);
for (int i = 0;i<dt.Rows.Count ;i++ )
{
dataGridView2.Rows[i+1].Cells[0].Value = dt.Rows[i]["1"].ToString();
dataGridView2.Rows[i+1].Cells[1].Value =Image.FromFile(dt.Rows[i]["2"].ToString());
}//加上tanghuawei说的方法
private void dataGridView2_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if ((e.RowIndex < 2 || e.RowIndex > 7) &&
e.ColumnIndex == 1)
{
e.Value = null;
}
}
还是有,只不过是没有图片预览的图片。