【问题标题】:Updating DatagridView Image Column in C#在 C# 中更新 DatagridView 图像列
【发布时间】:2020-12-18 12:53:13
【问题描述】:

我正在尝试更新由数据表填充的 datagridview。

启动时显示的是 (Properties.Resources.database) 而不是 (Properties.Resources.completed)。

        DataTable dtStores = new DataTable();
        dtStores.Columns.Add("Total");
        dtStores.Columns.Add("Store");
        dtStores.Columns.Add("Status",typeof(Image));

        DataRow rStore = dtStores.NewRow();
        rStore["Total"] = "";
        rStore["Store"] = "Supermarket";
        rStore["Status"] = Properties.Resources.database;
        dtStores.Rows.Add(rStore);

        dataGridView1.DataSource = dtStores;
        
        DataGridViewRow dGRVStore = dataGridView1.Rows[0];

        DataGridViewImageCell imgStatus = new DataGridViewImageCell();

        imgStatus.Value = Properties.Resources.completed;
        dGRVStore.Cells["Status"] = imgStatus ; dataGridView1.Refresh();

【问题讨论】:

  • DGV 绑定到 DataTable,所以更新存储在 DataTable 中的值而不是 DGV。
  • 谢谢。我之所以要捕获网格中的所有数据是为了修改并显示给用户,而不需要修改DT并重新绑定它。我可以处理 dGRVStore.Cells["Total"].Value = "5"; 之类的文本但它有图像的方式吗?
  • 我找到的一种方法是这个.. dataGridView1["Status", 0].Value = Properties.Resources.completed;

标签: c# winforms datatable datagridview datagridviewcolumn


【解决方案1】:

dataGridView1["Status", 0].Value = Properties.Resources.completed;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 2012-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多