1. Trang chủ
  2. » Giáo án - Bài giảng

Chapter 8 Implementing Data - Bound Controls

16 331 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 16
Dung lượng 114,88 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Chapter 8 Lesson 1: Creating a Data-Bound Form with the Data Sources Wizard Lesson 2: Implementing Data-Bound Controls Lesson 3: Working with the DataGridView... Lesson 1: Creating a

Trang 1

Chapter 8

Implementing Data-Bound Controls

Trang 2

Chapter 8

 Lesson 1: Creating a Data-Bound Form with the Data Sources Wizard

 Lesson 2: Implementing Data-Bound

Controls

 Lesson 3: Working with the DataGridView

Trang 3

Lesson 1: Creating a Data-Bound Form with the Data Sources Wizard

 What is Data-Bound controls?

– Bound and Un-Bound mode

– Data-bound controls are WinForms controls those can

easily bind with data components: DataGrid, ListBox, and a ComboBox

– have properties, which you can set as a data component

and theyre ready to present your data in WinForms:

DataSource,DisplayMember, DataMember

Dataset (Rows)

ID, Name… Dataset (Rows)Dataset (Rows)

Dataset (Rows) Position???

Trang 4

Lesson 1: Creating a Data-Bound Form with the Data Sources Wizard

 DEMO

– Creating a Data-Bound Windows Form

– Ex p411

Trang 5

 Track record position

– MoveNext, MovePrevious…

 Change data in datasource

– Add, Delete, EndEdit

Dataset (Rows)

ID, Name… Dataset (Rows)Dataset (Rows)

Dataset (Rows) BindinhSource

Trang 6

Lesson 2: Implementing Data-Bound Controls

– Simple data binding: displaying a single element

 BindingSource productsBindingSource = New BindingSource(NorthwindDataSet1,

“Products");

 TextBox1.DataBindings.Add("Text", productsBindingSource, "ProductName");

Trang 7

Lesson 2: Implementing Data-Bound Controls

 Binding Controls to Data

– Complex data binding: binding a control to more than one source of data

 BindingSource customersBindingSource=New BindingSource(NorthwindDataSet1, "Customers");

 DataGridView1.DataSource = customersBindingSource;

– Or

 DataGridView1.DataSource = NorthwindDataSet1;

 DataGridView1.DataMember = "Customers“;

Trang 8

Lesson 2: Implementing Data-Bound Controls

 Navigating Records in a DataSet

– use a BindingNavigator component.

– Assign the BindingNavigator.BindingSource

property to BindingSource component

Trang 9

Lesson 3: Binding with Listbox/Combobox

 Using unBound-mode

– Add items manually

 Using bound-mode

– Single table

– Two tables

 Core properties

– Datasource

– DataMember

– Displaymember

– ValueMember

 SeletectedValue

– BindingSource

– Example

Trang 10

Lesson 3: Binding with Listbox/Combobox

 Binding with single table

– DataSource

– DisplayMember

– ValueMember

 Return value:

– SelectedValue

Text

Trang 11

Lesson 3: Binding with Listbox/Combobox

 Binding with 2 tables

– DataSource

– DisplayMember

– ValueMember

 Binding with

– SelectedValue

Trang 12

Lesson 3: Working with the

DataGridView

 Configuring DataGridView Columns

Trang 13

Lesson 3: Working with the

DataGridView

 Adding Columns to a DataGridView

– Wizard (design time)

 Adding Columns to a DataGridView (p428)

– Dim ProductNameColumn As New

DataGridViewTextBoxColumn

– ProductNameColumn.Name = "ProductName"

– ProductNameColumn.HeaderText = "Product Name"

– ProductNameColumn.ValueType =

System.Type.GetType("System.String")

– DataGridView1.Columns.Add(ProductNameColumn)

Trang 14

Lesson 3: Working with the

DataGridView

 Determining the Clicked Cell in

DataGridView

– use the DataGridView.CurrentCell property

 Dim CurrentCellValue As String

 CurrentCellValue = CustomersDataGridView.CurrentCell.Value.ToString

Trang 15

Lesson 3: Working with the

DataGridView

 ErrorText proerty of row and cell in row

 Validating Input in the DataGridView

– handle the DataGridView CellValidating event and cancel the edit if the value fails validation (is raised when a cell loses focus.)

Trang 16

Lesson 3: Working with the

DataGridView

 Format a DataGridView Using Styles

– DefaultCellStyle

– AlternatingRowsDefaultCellStyle

 Lab: Working with the DataGridView

– Page 431

Ngày đăng: 13/05/2014, 12:19

TỪ KHÓA LIÊN QUAN