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

Recommended Answers

All 4 Replies

Can you show what have you done so far?

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.

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.

It worked,thanks you so much ..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.