簡體   English   中英

在DataGridViewImageColumn綁定文本字段中顯示圖像

[英]Showing image in a DataGridViewImageColumn binding text-field

我工作的一個WindowsForm項目,並在我的表單我有一個DataGridViewDataGridViewImageColumn它必須顯示行的狀態使用圖像(啟用/禁用)。

我有一個DataTable ,我綁定到我的數據網格。 在此表中,有一列是每行的狀態 ,是一個文本字段。

如何將此列綁定到顯示正確圖像的DataGridViewImageColumn

每當我對如何在DataGridView中執行操作有疑問時,請先咨詢Microsoft的FAQ。

http://www.windowsclient.net/Samples/Go%20To%20Market/DataGridView/DataGridView%20FAQ.doc

通常我在這種情況下做的是處理CellFormatting事件以根據單元格中的值設置圖像。

所以我將我的圖像存儲在像圖像列表之類的東西中,然后在CellFormatting中使用如下代碼:

private void dgv_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (dgv.Columns[e.ColumnIndex].Name == "status")
    {
        if (e.Value != null)
        {
            if (e.Value.ToString() == "1")
            {
                e.Value = imageList1.Images[1];
            }
            else
            {
                e.Value = imageList1.Images[2];
            }
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM