需要绑定的数据类型的属性,必须加上get;set;,否则无法绑定
窗口加载时绑定数据:
private void FormIO_Load(object sender, EventArgs e)
{
List<Test> lists = new List<Test>()
{
new Test("aa","bb",Properties.Resources.ok_16),
new Test("cc","dd",Properties.Resources.normal_16),
new Test("ee","ff",Properties.Resources.yes_16)
};
kryptonDataGridView1.DataSource = lists;
}
Test模型结构如下,如果属性不加上get set,则无法绑定数据:
public class Test
{
//public string S1;//错误,无法绑定到datagridview
//public string S2;//错误,无法绑定到datagridview
//public Image Image;//错误,无法绑定到datagridview
public string S1 { get; set; }
public string S2 { get; set; }
public Image Image { get; set; }
public Test(string s1, string s2, Image image)
{
this.S1 = s1;
this.S2 = s2;
this.Image = image;
}
}