C#DataGridView ImageColumn

时间:2018-11-21 14:18:03

标签: c# datagridview datagridviewimagecolumn

当更改包含dataGridView的用户控件的可见性时,

DataGridView图像列将为空。代码如下;

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 个答案:

答案 0 :(得分:0)

尝试一下:

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));