我有课
public class CLASS_K
{
public static List<AA> simpleList = new List<AA>()
{
new AA(){NNN = "o1", NNN2 = "o1a"},
new AA(){NNN = "o2", NNN2 = "o2a"}
};
public class AA
{
public string NNN { get; set; }
public string NNN2 { get; set; }
}
}
我为label设置了绑定:
label1.DataBindings.Add("text", CLASS_K.simpleList[1], "NNN");
如何将dataSource从标签转换为AA类?
我的错误想法:
BindingSource binding = (BindingSource)label1.DataBindings[0].DataSource;
CLASS_K.AA b = (CLASS_K.AA) binding.DataSource;
答案 0 :(得分:0)
DataSource
包含CLASS_K.AA
类型的对象,请尝试以下操作:
if (label1.DataBindings.Count != 0)
{
var b = label1.DataBindings[0].DataSource as CLASS_K.AA;
if (b != null)
{
// do something...
}
}