C# - How Display Images In Datagridview Row Cells Using C#
____________________________________________________
In This C# Code We Will See How To Create Datagridview Image Column And Add Images To The Column In CSharp Programming Language .
Project Source Code:
In This C# Code We Will See How To Create Datagridview Image Column And Add Images To The Column In CSharp Programming Language .
Project Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class CSharp_Populate_Datagridview_With_Images : Form
{
public CSharp_Populate_Datagridview_With_Images()
{
InitializeComponent();
}
private void CSharp_Populate_Datagridview_With_Images_Load(object sender, EventArgs e)
{
// create Datagridview image column
DataGridViewImageColumn dgvImageColumn = new DataGridViewImageColumn();
// set header text to the column
dgvImageColumn.HeaderText = "Image";
// display the entire image
dgvImageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch;
// create Datagridview text column
DataGridViewTextBoxColumn dgvIdColumn = new DataGridViewTextBoxColumn();
dgvIdColumn.HeaderText = "Id";
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView1.RowTemplate.Height = 130;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.Columns.Add(dgvIdColumn);
dataGridView1.Columns.Add(dgvImageColumn);
// create and add images to the dataGridView
Image img1;
img1 = Image.FromFile(@"D:\Images\img1.jpg");
dataGridView1.Rows.Add("RTUIKJGRR",img1);
Image img2;
img2 = Image.FromFile(@"D:\Images\img2.jpg");
dataGridView1.Rows.Add("AZERTYU", img2);
Image img3;
img3 = Image.FromFile(@"D:\Images\img3.jpg");
dataGridView1.Rows.Add("MLKJHG", img3);
Image img4;
img4 = Image.FromFile(@"D:\Images\img4.jpg");
dataGridView1.Rows.Add("FGHJKLKUY", img4);
Image img5;
img5 = Image.FromFile(@"D:\Images\img5.jpg");
dataGridView1.Rows.Add("VBJHGF", img5);
}
}
}
OutPut :
Bagikan
C# - How To Populate Datagridview With Images In C#
4/
5
Oleh
insurance