Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I've already made a datagridview and show data and image in each row but my customer asked me to make expand button to show more images(about 16 images) below the selected row when he clicks a button or mouse over on each row.
How can I implement this?
Thank you in advance

What I have tried:

private void datagridview1_CellClick(object sender, DataGridViewCellEventArgs e)
{

if (e.ColumnIndex == btnColumnIdx)
{
string idx = dgv_main.Rows[e.RowIndex].Cells["idx"].Value.ToString();

}

}
Posted
Updated 23-May-16 23:52pm
v2

Hi try this.it helpfull for you .

System.Drawing.Image Image = System.Drawing.Image.FromFile(Application.StartupPath + "\\Images\\AddrDef.gif");
System.Drawing.Imaging.ImageFormat ImageFormat = System.Drawing.Imaging.ImageFormat.Gif;

string strImage = ImageToBase64(Image, ImageFormat);
dgv_main.Rows[e.RowIndex].Cells["idx"].Value = strImage;
 
Share this answer
 
Comments
hapiten 24-May-16 3:38am    
Thank you for your help but it says ImageToBase64 doesn't exist.
I want to add an another row below the selected row.
Shouldn't I use datagridview1.rows.insert?
This might be of interest to you: Image Thumbnail Preview in DataGridView[^]

If you use a BindingList (recommended) then you can do it like this:
C#
using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace TestForm1
{
    public partial class Form1 : Form
    {
        /// <summary>
        /// The binding list reference.
        /// </summary>
        private BindingList<MyClass> masterBindingList;

        public Form1()
        {
            InitializeComponent();
            this.Init();
        }

        private void Init()
        {
            this.masterBindingList = new BindingList<MyClass>();
            this.dataGridViewMaster.DataSource = this.masterBindingList;
        }

        private void ButtonAddRowClick(object sender, EventArgs e)
        {
            var rowIndex = this.dataGridViewMaster.RowCount;
            this.AddRow(rowIndex);
            this.ScrollToRow(rowIndex);
        }

        /// <summary>
        /// Add new row via the BindingList.
        /// </summary>
        private void AddRow(int rowIndex)
        {
            this.masterBindingList.Add(new MyClass { Title = "Row " + rowIndex.ToString() });
        }

        private void ScrollToRow(int rowIndex)
        {
            this.dataGridViewMaster.ClearSelection();
            this.dataGridViewMaster.FirstDisplayedScrollingRowIndex = rowIndex;
            this.dataGridViewMaster.Focus();
        }
        /// <summary>
        /// Simple class with one string.
        /// </summary>
        public class MyClass
        {
            public string Title { get; set; }
        }
    }
}
 
Share this answer
 
v7
Comments
hapiten 24-May-16 8:42am    
How do I get "this.masterBindingList.Add(new MyClass());"?
RickZeeland 24-May-16 9:22am    
I will update the solution, in the meantime I can recommend this excellent article: http://www.codeproject.com/Articles/24656/A-Detailed-Data-Binding-Tutorial
hapiten 24-May-16 10:49am    
It says masterBindingList is null
RickZeeland 24-May-16 13:43pm    
Updated solution to a fully working example :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900