1.DataGridView Data Binding
1 namespaceWindowsFormsApplication12 {3 Public Partial classForm1:form4 {5 PrivateList<student> _students =NewList<student>();6 7 PublicForm1 ()8 {9 InitializeComponent ();Ten One_students. ADD (NewStudent () {Name ="Huang Yong", age = -, School ="Harbin University of Commerce" }); A -_students. ADD (NewStudent () {Name ="Ming He", age = -, School ="Hunan Polytechnic University" }); - the_students. ADD (NewStudent () {Name ="Tommy", age = +, School ="University of Hong Kong" }); - + varBindingList =NewBindinglist<student>(_students); - atDatagridview1.datasource =bindingList; - - } - - Private voidButton1_Click (Objectsender, EventArgs e) - { in varStudent = _students. FirstOrDefault (item = Item). Name.equals ("Ming He")); - to if(Student! =NULL) + { - //dynamically refreshes the UI theStudent. Name =" -"; * } $ }Panax Notoginseng } - the Public classstudent:inotifypropertychanged + { A Public EventPropertyChangedEventHandler propertychanged; the + PrivateString _name; - PrivateInt32 _age; $ PrivateString _school; $ - PublicString Name - { the Get - {Wuyi return_name; the } - Set Wu { - if(Value! =_name) About { $_name =value; - This. Notifypropertychanged ("Name"); - } - } A } + the PublicInt32 Age - { $ Get the { the return_age; the } the Set - { in if(Value! =_age) the { the_age =value; About This. Notifypropertychanged (" Age"); the } the } the } + - PublicString School the {Bayi Get the { the return_school; - } - Set the { the if(Value! =_school) the { the_school =value; - This. Notifypropertychanged ("School"); the } the } the }94 the Private voidNotifypropertychanged (stringname) the { the if(PropertyChanged! =NULL)98 { AboutPropertyChanged ( This,NewPropertyChangedEventArgs (name)); - }101 }102 }103}
Winform Data Binding