据我所知DataGridView控件及其相关类是 旨在成为一个灵活,可扩展的显示和显示系统 编辑表格数据。我们可以在一列中添加一个Image控件 DataGridView的。设置列Image属性会生成该图像 默认情况下显示该列中的所有单元格。该 以下C#程序显示如何在a的列中添加Image DataGridView控件。
任何人都可以给我一个例子来将图像添加到C#DataGridView
答案 0 :(得分:5)
希望这会有所帮助
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.ColumnCount = 3;
dataGridView1.Columns[0].Name = "Product ID";
dataGridView1.Columns[1].Name = "Product Name";
dataGridView1.Columns[2].Name = "Product Price";
string[] row = new string[] { "1", "Product 1", "1000" };
dataGridView1.Rows.Add(row);
row = new string[] { "2", "Product 2", "2000" };
dataGridView1.Rows.Add(row);
row = new string[] { "3", "Product 3", "3000" };
dataGridView1.Rows.Add(row);
row = new string[] { "4", "Product 4", "4000" };
dataGridView1.Rows.Add(row);
DataGridViewImageColumn img = new DataGridViewImageColumn();
Image image = Image.FromFile("Image Path");
img.Image = image;
dataGridView1.Columns.Add(img);
img.HeaderText = "Image";
img.Name = "img";
}
答案 1 :(得分:1)
此链接说明如何将图像添加到datagridview
http://technico.qnownow.com/display-images-from-database-in-asp-net-gridview-using-httphandler/