none
Assigning Value to the dataGridViewCelll is always coming null RRS feed

  • Question

  • Hi

    I am using datagridview with the firstcolumn as image column. In the cellPainting event of the datagridview i assigning different images to each cell. I am assigning to each cell from the imagelist control. the issues is every time if assign the value to each cell from the imagelist control it comes as null, although the imagelist control has images at the specfic indexes, due o which broken image are appearing whn the grid is appearing.

    The following code i am uisng in the cellpainting event 

     

    private void dgvInbox_CellPainting(object sender, System.Windows.Forms.DataGridViewCellPaintingEventArgs e)

    {

     

    if (!(e.RowIndex < 0))

    {

    inbox = (((sender

    as DataGridView).Rows[e.RowIndex].DataBoundItem) as Inbox);

     

    if (inbox != null)

    {

     

    switch (inbox.Format)

    {

     

    case "pdf":

     

    this.dgvInbox.Rows[e.RowIndex].Cells[0].Value = this.imgListinbox.Images[0];

     

    break;

     

    default:

     

    this.dgvInbox.Rows[e.RowIndex].Cells[0].Value = this.imgListinbox.Images[1];

     

    break;

    }

    }

    }

     

    }

      Any suggestion is appreciated

    Thanks
    Gaurav
    Thursday, November 19, 2009 3:44 PM

Answers

  • This issue only happen if we set the virtual mode of the datagridView to true, otherwise it doesnot happens 
    Thursday, November 19, 2009 7:14 PM
  • Hi sawhneyg,

    When you set the VirtualMode to true, it means you enable the virtual mode, so you have to implement it. You can follow the document below to implement it:
    http://msdn.microsoft.com/en-us/library/15a31akc.aspx

    Regards,
    Aland Li
    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Thursday, November 26, 2009 4:32 AM
    Moderator

All replies

  • This issue only happen if we set the virtual mode of the datagridView to true, otherwise it doesnot happens 
    Thursday, November 19, 2009 7:14 PM
  • Hi sawhneyg,

    Could you please let me know if you implemented the virtual mode of the DataGridView?

    I have read the code you provided, but did not find out any apprant errors. This is the orded code:
           private void dgvInbox_CellPainting(object sender, System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
            {
                if (!(e.RowIndex < 0))
                {
                    inbox = (((sender as DataGridView).Rows[e.RowIndex].DataBoundItem) as Inbox);
                    if (inbox != null)
                    {
                        switch (inbox.Format)
                        {
                            case "pdf":
                                this.dgvInbox.Rows[e.RowIndex].Cells[0].Value = this.imgListinbox.Images[0];
                                break;
                            default: this.dgvInbox.Rows[e.RowIndex].Cells[0].Value = this.imgListinbox.Images[1];
                                break;
                        }
                    }
                }
            }
    Regards,
    Aland Li
    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Monday, November 23, 2009 8:20 AM
    Moderator
  • Hi Aland,

    Thanks for the reply. I had not implemented the virtual mode. This behaviour happens only when i set the virtualmode property of the datagridview to true and doesnot happens when i set the virtualmode to false.


    Regards,
    Gaurav
    Monday, November 23, 2009 2:27 PM
  • Hi sawhneyg,

    When you set the VirtualMode to true, it means you enable the virtual mode, so you have to implement it. You can follow the document below to implement it:
    http://msdn.microsoft.com/en-us/library/15a31akc.aspx

    Regards,
    Aland Li
    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Thursday, November 26, 2009 4:32 AM
    Moderator