Grid view Control With image Control And How to Insert Images in Grid View in C#

gridView Control:
In this tutorial, you will learn how to use the DataGridView control and its supporting classes, in detail. Displaying data in a tabular format is a task you are likely to perform frequently. The DataGridView control is designed to be a complete solution for displaying tabular data with Windows Forms. The DataGridView control is highly configurable and extensible, and it provides many properties, methods, and events to customize its appearance and behavior gridView Control. 






C#(Code)...........


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Insert_images_in_Datagrid_View
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
                OpenFileDialog opnfd = new OpenFileDialog(); 
                        opnfd.Filter = "Image Files (*.jpg;*.jpeg;.*.gif;)|*.jpg;*.jpeg;.*.gif"; 
                        if (opnfd.ShowDialog() == DialogResult.OK) 
                        { 
                        pictureBox1.Image = new Bitmap(opnfd.FileName); 
             
                        } 

        }

        private void Upload_Click(object sender, EventArgs e)
        {
            MemoryStream mmst = new MemoryStream(); 
                        pictureBox1.Image.Save(mmst, pictureBox1.Image.RawFormat); 
                        byte[] img = mmst.ToArray(); 
                        dataGridView1.Rows.Add(img); 

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DataGridViewImageColumn dgvimcl = new DataGridViewImageColumn();
            dgvimcl.HeaderText = "Upload Images";
            dgvimcl.ImageLayout = DataGridViewImageCellLayout.Stretch;
            dataGridView1.Columns.Add(dgvimcl);
            dataGridView1.RowTemplate.Height = 250;
            dataGridView1.AllowUserToAddRows = true;


        }
    }
}

Comments