控件类型作为数据列的数据类型

Control type as datatype of datacolumn

我在 vb.net 中完成了此操作,但似乎无法在 c# 中使用它。我正在尝试将新 datacolumndatatype 设置为标签(或 System.Windows.Forms.Label),以便此数据表可以引用表单上的控件以加快索引速度。代码片段:

DataColumn dc = new DataColumn {DataType = System.Windows.Forms.Label, ColumnName = "labelDate"};

抛出错误“'Label' 是一种类型,在给定上下文中无效”。同时,"DataType" 需要 "Type",所以我不确定这里有什么问题。

想出来了,把答案留在这里以防对任何人有帮助

DataColumn dc = new DataColumn {DataType = typeof(Label), ColumnName = "labelDate"};