Docsity

Data Binding - Embedded Systems - Lecture Slides | CS 5950, Study notes of Computer Science

Toggle sidebar
bg1
Data Binding
Data Binding
How to Populate Form Controls?
Specify the data in the control’s properties
Not dynamic: can’t get data from a database
Write code that uses the control’s object model
This is okay if you need to populate a simple value or
list, but quickly gets too complicated for populating
sophisticated displays
Data binding
Create an object that holds the data
(DataSet, Array, string, int, etc.)
Associate that object with the control
pf3
pf4
pf5

Partial preview of the text

Download Data Binding - Embedded Systems - Lecture Slides | CS 5950 and more Study notes Computer Science in PDF only on Docsity!

Data Binding

Data Binding

How to Populate Form Controls?

Š Specify the data in the control’s properties „ Not dynamic: can’t get data from a database

Š Write code that uses the control’s object model „ This is okay if you need to populate a simple value or list, but quickly gets too complicated for populating sophisticated displays

Š Data binding „ Create an object that holds the data (DataSet, Array, string, int, etc.) „ Associate that object with the control

Data Binding

What Is It?

Š Provides a single simple yet powerful way to populate Web controls with data „ Enables clean separation of code from UI Š Supports binding to any data source „ Properties, expressions, method calls „ Collections (Array, Hashtable, etc.) „ DataSet, DataTable, DataView, DataReader „ XML

Data Sources Window

Drag and drop operations

Š Dragging/dropping tables from Data Sources Window onto form will create instances of: „ DataSet, TableAdapter, BindingSource „ BindingNavigator with nav/add/delete/save controls „ Bound control(s) Š Use Data Sources window to configure: „ Whether table will be edited with DataGridView or “Details” mode (individual controls) „ Mapping of detail control types to column data types (shortcut to Windows Forms Designer/Data UI Customization node in Options dialog)

Strongly-Typed DataSets

Š As before „ Consist of DataTables, Relations, Constraints „ Drag/drop from Server Explorer is supported „ Based on XML schema and code-behind class Š Also consists of TableAdapters „ Encapsulate a DataAdapter and a Connection Š Enhanced Typed Dataset Designer „ Instead of XSD Designer earlier Š Partial class support

TableAdapters

Š Have Queries (methods for handling selects, updates, inserts, deletes)

Š Queries exists as methods

Š Fully customizable and extendable

Š Can be re-used across multiple forms

Š Have Connection property „ Connection string typically stored in web/app.config; default value applied in WinForms apps.

BindingSource: Basics

Š Acts as “broker” between bound controls and actual data source Š DataSource, DataMember „ Point to typed DataSet, DataTable

Š AllowEdit, AllowNew, AllowRemove Š Filter, Sort properties „ Run time: RemoveFilter, RemoveSort methods

BindingSource

Run time members

Š MovePrevious, MoveNext, MoveFirst, MoveLast, Position, Count properties (handles all navigation)

Š AddNew, Insert(index, obj) methods

Š RemoveCurrent , RemoveAt(index), Remove(obj)

Š EndEdit, CancelEdit methods „ Works with edits and inserts/new’s

Š Use of most of these is optional due to…

Complex and Simple Binding Scenarios

Š Complex Binding „ DataGridView.DataSource = BindingSource

Š SimpleBinding „ TextBox.Text (and other controls/string-based properties) bound to member of BindingSource „ BindingNavigator.BindingSource = BindingSource