【发布时间】: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