cst238 week 7 questions / concerns? announcements – hw#2 due today (project concept/preliminary...
TRANSCRIPT
![Page 1: CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last](https://reader035.vdocuments.mx/reader035/viewer/2022071807/56649e4f5503460f94b469a6/html5/thumbnails/1.jpg)
CST238 Week 7• Questions / Concerns?• Announcements
– HW#2 due today (project concept/preliminary design)– Check-off Take Home lab#6
• Friday is the last day to withdraw from class. • GUI Bloopers presentations (#3)• New topics
– Data Binding• Coming up:
– GUI Presentation #5 & #6 next Monday– WPF vs Windows Forms– Work on Final Project
• Take Home Lab#7
![Page 2: CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last](https://reader035.vdocuments.mx/reader035/viewer/2022071807/56649e4f5503460f94b469a6/html5/thumbnails/2.jpg)
Why Data Binding?• Windows Forms Problem– There is no clear separation of user interface and
data. – Controls and data are tightly coupled.
• Data binding doesn’t address this problem of tightly coupled UI and data, but it saves programmers some work:– Don’t have to write code to move data in and out
of controls.
![Page 3: CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last](https://reader035.vdocuments.mx/reader035/viewer/2022071807/56649e4f5503460f94b469a6/html5/thumbnails/3.jpg)
Data Binding• One-way: Automatically populating controls
with data– Set a few properties
• Two-way: Automatically propagating changes to data– From control to data source
![Page 4: CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last](https://reader035.vdocuments.mx/reader035/viewer/2022071807/56649e4f5503460f94b469a6/html5/thumbnails/4.jpg)
Data Binding• Core capability of .NET controls– Web and Windows– Built in at base Control level
• Interface-based– An interface contains only the signatures of
methods, properties, or events . – A class or struct that implements the interface
must implement the members of the interface that are specified in the interface definition.
![Page 5: CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last](https://reader035.vdocuments.mx/reader035/viewer/2022071807/56649e4f5503460f94b469a6/html5/thumbnails/5.jpg)
Data Binding• Simple data binding
• Bind a single value from a data collection to a single control property• Ex: customer name to Text property on Textbox
• Complex data binding• Bind collection of data to control that presents multiple
values from collection• Ex: customers table in grid, customer name values in
combo box.
![Page 6: CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last](https://reader035.vdocuments.mx/reader035/viewer/2022071807/56649e4f5503460f94b469a6/html5/thumbnails/6.jpg)
Data Binding• Simple data binding– Create a Binding object– Add to DataBindings collection of control
• Complex data binding– Set data source– Set data member– DisplayMember and ValueMember for ComboBox
and List Box controls
![Page 7: CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last](https://reader035.vdocuments.mx/reader035/viewer/2022071807/56649e4f5503460f94b469a6/html5/thumbnails/7.jpg)
C#: Fields & Properties of an object• Fields – Internal data / state of an object. (ex. age)– Fields should not be public. – How do you access the field then?• Through methods (GetAge, SetAge)
• Method– Behavior. – Getters/setters are not really behavior though.
• Property– Another way to access the field
![Page 8: CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last](https://reader035.vdocuments.mx/reader035/viewer/2022071807/56649e4f5503460f94b469a6/html5/thumbnails/8.jpg)
C#: Propertyclass Student{ private int age; //private field
public int Age //Public property { get {return age;} set { age = value;} }…
Student aStudent = new Student();aStudent.age = 35;aStudent.Age = 35; //value is 35 if (aStudent.Age == 35) …
![Page 9: CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last](https://reader035.vdocuments.mx/reader035/viewer/2022071807/56649e4f5503460f94b469a6/html5/thumbnails/9.jpg)
C#: Propertyclass Student{ private int age; //private field
public int Age //Public property { get {return age;} set { age = value;} }…
public int Age {get; set;}
![Page 10: CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last](https://reader035.vdocuments.mx/reader035/viewer/2022071807/56649e4f5503460f94b469a6/html5/thumbnails/10.jpg)
Simple Data Binding• Binding object which binds control properties to object properties.
aStudent = new Student("Smith", "Gail", "918111111", true); LastnameBox.DataBindings.Add("Text", aStudent, "Lastname");FirstnameBox.DataBindings.Add("Text", aStudent, "Firstname");IDBox.DataBindings.Add("Text", aStudent, "ID");RegisteredCheckbox.DataBindings.Add("Checked", aStudent, "Registered");
aStudent
Lastname SmithFirstname Gail
ID 918111111Registered true
![Page 11: CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last](https://reader035.vdocuments.mx/reader035/viewer/2022071807/56649e4f5503460f94b469a6/html5/thumbnails/11.jpg)
Simple Data Binding• Binding object which binds control properties to object properties.
aStudent = new Student("Smith", "Gail", "918111111", true); LastnameBox.DataBindings.Add("Text", aStudent, "Lastname“, true, DataSourceUpdateMode.OnPropertyChanged);FirstnameBox.DataBindings.Add("Text", aStudent, "Firstname“, true, DataSourceUpdateMode.OnPropertyChanged);IDBox.DataBindings.Add("Text", aStudent, "ID“, true, DataSourceUpdateMode.Never);RegisteredCheckbox.DataBindings.Add("Checked", aStudent, "Registered“, true, DataSourceUpdateMode.OnPropertyChanged);
Lastname SmithFirstname Gail
ID 918111111Registered true
![Page 12: CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last](https://reader035.vdocuments.mx/reader035/viewer/2022071807/56649e4f5503460f94b469a6/html5/thumbnails/12.jpg)
Complex Data Binding• Bind a collection of data to a control• Collection must implement IList or IListSource interface
• Student Major List demo– Tab Control– Combo box & binding
• DisplayMember (MajorName object property) , ValueMember (MajorCode object property)
• DataSource
– Listbox, query & binding• DataSource, DisplayMember
– Datagrid view• DataSource
![Page 13: CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last](https://reader035.vdocuments.mx/reader035/viewer/2022071807/56649e4f5503460f94b469a6/html5/thumbnails/13.jpg)
Take-Home Lab #7• Create a Category class with 2 properties:– CategoryID (int)– CategoryName (string)
• Create a Product class with 4 properties:– ProductName (string)– CategoryID (int)– Unit Price (float)– OnSale (bool)
![Page 14: CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last](https://reader035.vdocuments.mx/reader035/viewer/2022071807/56649e4f5503460f94b469a6/html5/thumbnails/14.jpg)
Take Home Lab #7• Create a form:– Combo box to show the list of product categories– Listbox to show the products– Textboxes and checkbox bound to selected
product.