Commit f8a884f8 熊本熊kumamon

修正 UCDataGridView 的 DataSource 是 DataTable 資料無法正常顯示

1 个父辈 add05d52
...@@ -207,7 +207,7 @@ namespace HZH_Controls.Controls ...@@ -207,7 +207,7 @@ namespace HZH_Controls.Controls
{ {
if (value != null) if (value != null)
{ {
if (!(m_dataSource is DataTable) && (!typeof(IList).IsAssignableFrom(value.GetType()))) if (!(value is DataTable) && (!typeof(IList).IsAssignableFrom(value.GetType())))
{ {
throw new Exception("数据源不是有效的数据类型,请使用Datatable或列表"); throw new Exception("数据源不是有效的数据类型,请使用Datatable或列表");
} }
......
...@@ -158,17 +158,32 @@ namespace HZH_Controls.Controls ...@@ -158,17 +158,32 @@ namespace HZH_Controls.Controls
var cs = this.panCells.Controls.Find("lbl_" + com.DataField, false); var cs = this.panCells.Controls.Find("lbl_" + com.DataField, false);
if (cs != null && cs.Length > 0) if (cs != null && cs.Length > 0)
{ {
var pro = DataSource.GetType().GetProperty(com.DataField); if (DataSource is DataRow row)
if (pro != null)
{ {
var value = pro.GetValue(DataSource, null);
if (com.Format != null) if (com.Format != null)
{ {
cs[0].Text = com.Format(value); cs[0].Text = com.Format(row[com.DataField]);
} }
else else
{ {
cs[0].Text = value.ToStringExt(); cs[0].Text = row[com.DataField].ToStringExt();
}
}
else
{
var pro = DataSource.GetType().GetProperty(com.DataField);
if (pro != null)
{
var value = pro.GetValue(DataSource, null);
if (com.Format != null)
{
cs[0].Text = com.Format(value);
}
else
{
cs[0].Text = value.ToStringExt();
}
} }
} }
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!