binding gridview to objects

ε祈祈猫儿з 提交于 2019-12-25 10:05:12

问题


My C# app contains a Data Object like this:

public class Data
 {
    public class a {get;set;}
    public class b {get;set;}
 }

public class a
{
  public int first {get;set;}
}
public class b
{
  public int second{get;set;}
 }

I initialize my data when the application starts and my data changes evey time the app is running.

I have a dataGridView and I want to bind to the first property and to second property. The DataGrid contains two columns, that bound to first and to second property.

How can I do this binding? I don't want to change my dataSource nor do I want to add data.

NOTE: Remember that my data can change every time the app running.


回答1:


Use INotifyPropertyChanged Interface and implement NotifyPropertyChanged() method in your source (in your case Class a and b). You should call NotifyPropertyChanged every time the proeprty value changes.

Then you can bind to UI controls that support INOtifyProperyChanged... that's it.

Mark response as answered.



来源:https://stackoverflow.com/questions/3591081/binding-gridview-to-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!