0

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;
    }
}
Aykut Demirci
  • 168
  • 4
  • 19
  • As a side note you need to dispose your `Images` or you will soon enough see OutOfMemoryException if you do not. – Rafal Nov 21 '18 at 14:34
  • `Image Column is getting null when...` doesnt tell us what problem we are supposed to solve. We need to know the exception and line of code. Also, you wont have a `Resources` folder when deployed and may not have permission to access it if there was. – Ňɏssa Pøngjǣrdenlarp Nov 21 '18 at 15:39

1 Answers1

0

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));
begovsky
  • 1
  • 1