Thursday, 18 October 2012

add image in DataGridView windows in c#.net

 dataGridView1.ColumnCount = 2;
            dataGridView1.Columns[0].Name = "EID";
            dataGridView1.Columns[1].Name = "NAME";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string[] r = new string[] { dt.Rows[i].ItemArray[0].ToString(), dt.Rows[i].ItemArray[1].ToString() };
                dataGridView1.Rows.Add(r);
            }
            DataGridViewImageColumn dgv = new DataGridViewImageColumn();
            dgv.HeaderText = "image";
            dgv.ImageLayout = (System.Windows.Forms.DataGridViewImageCellLayout)ImageLayout.Stretch;
            dgv.Image = Image.FromFile(
                @"c:\users\chinmaya\documents\visual studio 2010\Projects\WindowsFormsApplication11\WindowsFormsApplication11\Resources\Koala.jpg");
            dataGridView1.Columns.Add(dgv);

No comments:

Post a Comment