C# DataGridView ImageColumn

53 views Asked by At

DataGridView Image Column is getting null when change the visibility of User Control that includes the dataGridView. Codes are below;

public partial class ReadingOrderListControl : UserControl
{
    private Image Pending { get { return Image.FromFile(@"..\..\Resources\pending.png"); } }
    private Image Completed { get { return Image.FromFile(@"..\..\Resources\completed.png"); } }

    private void ReadingOrderListControl_Load(object sender, EventArgs e)
    {
        GetOrderList();
    }

    private void GetOrderList()
    {
         dgv_ReadingOrders.DataSource = DbManager.GetReadingOrders();

         if (dgv_ReadingOrders.Rows[0].Cells["tamamlanma"].Value.ToString() == "1")
             dgv_ReadingOrders.Rows[0].Cells["tamamlanma_image"].Value = Completed;
         else
             dgv_ReadingOrders.Rows[0].Cells["tamamlanma_image"].Value = Pending;
    }
}
1

There are 1 answers

0
begovsky On

Try this:

if (dgv_ReadingOrders.Rows[0].Cells["tamamlanma"].Value.ToString() == "1")
dgv_ReadingOrders.Rows.Add(ID,...... , Bitmap.FromFile(Completed));
else
dgv_ReadingOrders.Rows.Add(ID,...... , Bitmap.FromFile(Pending));