0

Hi All,
I have a dataGridView control ,which I attach with a data source,this datasource can change over the time. Now ,the problem is ,after assigning the data source ,I add one more static column and trying to add image to the cells [ I've used DataGridViewImageCell and DataGridViewImageColumn,the images are different for different rows]. But for some reason I am not able to assign the Value property of the indivisual rows[0].Cell[0].Value.
Any pointer towards the problem ? Thanks in advance.

Regards
Sam

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by SamTheDevGuru
0

i have a similar setup in one of my apps. I'm not sure why you can't alter the values, i have no problems. I use the RowsAdded event to set the images and apply any styling to the rows:

private void dgvOrders_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            for (int i = 0; i < dgvOrders.RowCount; i++)
            {

                if (dgvOrders.Rows[i].Cells["printedDataGridViewTextBoxColumn"].Value != DBNull.Value)
                {
                    dgvOrders.Rows[i].Cells["Printed"].Value = imlIcons.Images["Printed"];
                }
                else
                {
                    dgvOrders.Rows[i].Cells["Printed"].Value = imlIcons.Images["blank"];
                }
                //... etc

I check all the rows since they are added at once, alternatively you can use the eventargs to find the number of rows added and the index of the first addition if you want to only process new rows.

0

This is from mind, but i think you can do this.

for (int i = 0; i < e.RowCount; i++)
{
      DataGridViewRow row = dgvOrders.Rows[e.RowIndex + i];
      if (row.Cells["printedDataGridViewTextBoxColumn"].Value != DBNull.Value)
      {
           row.Cells["Printed"].Value = imlIcons.Images["Printed"];
      }
      else
      {
           row.Cells["Printed"].Value = imlIcons.Images["blank"];
      }
}

Try something like that.

Edited by jbisono: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.