问题
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