locked
datagridviewcomboboxcell RRS feed

  • Question

  • I have one such instance of datagridviewcomboboxcell in a datagrid view. When the combobox is updated with a different value by the user, I need an image to be displayed in a different cell of the datagridview. How can I do that?

    This is what I've tried so far, without any success:

    private void generaldgv_MouseUp(object sender, EventArgs e)
            {
                if (activeCellColumn == 1 && activeCellRow == 3)
                {
                    generaldgv[5, 5].Value = img;
                }
            }
            private void generaldgvCellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
            {
                activeCellColumn = e.ColumnIndex;
                activeCellRow = e.RowIndex;
            }
            private void generaldgvEditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
            {
                if (activeCellColumn == 1 && activeCellRow == 3)
                {
                    generaldgv[5, 5].Value = img;
                }
            }

    Saturday, July 23, 2011 12:13 AM

Answers

  • If you wanna set an image into particular cell, you have to create dataGridViewImageCell:

    //where you want to add an image:
    DataGridViewImageCell imageCell = new DataGridViewImageCell();
    dataGridView1[colIndex, rowindex] = imageCell;
    imageCell.Value = img; //assign your image to the Value property
    



    Mitja
    • Proposed as answer by Cookie Luo Tuesday, July 26, 2011 3:22 AM
    • Marked as answer by Cookie Luo Wednesday, August 3, 2011 5:57 AM
    Saturday, July 23, 2011 1:26 AM