Copy-Paste images in DataGridWiew

Hello,

I have an application with a DataGridView. The table that I work with that DataGridView has a column where I need to put an image, therefore when I created the SQL table I defined that column as image.

When I run the application, I can copy text into the DataGridView by clicking the desired cell (so it changes from blue to white) and then right clicking the desired cell and selecting the Paste option.

Now when I want to do that with the image column, I can't even edit the cell (it stays in blue color).

What should I do to allow the copy-paste of images into the DataGridView

Thanks,

Carlos



Answer this question

Copy-Paste images in DataGridWiew

  • John.Doe

    Hi,

    The image in the database actually is byte array type. So, if you want to put the image into the cell of the datagridview, you'd first convert the image in clipboard into byte array, and then what reminds me is to register a hot key to "paste" the image, then refresh the control and update the DB.

    Thank you



  • shibin

    Except registering hot key, you may handle DataGridView.KeyDown event and use DataGridView.CurrentCell.ColumnIndex to determine if the pasting occurs in the image column, see the code logic below:

    private void dataGridView1_KeyDown(object sender, KeyEventArgs e)

    {

    if (e.Control == true && e.KeyCode == Keys.V)

    {

    if (this.dataGridView1.CurrentCell.ColumnIndex == this.Column1.Index)

    {

    //replace image in Column1 with clipboard image

    }

    }

    }

    Thank you



  • Copy-Paste images in DataGridWiew