📄 bindingdemoform8.vb
字号:
Me.lblSalary.Size = New System.Drawing.Size(60, 17)
Me.lblSalary.TabIndex = 70
Me.lblSalary.Text = "当前工资:"
'
'lblBirthday
'
Me.lblBirthday.AutoSize = True
Me.lblBirthday.Location = New System.Drawing.Point(72, 137)
Me.lblBirthday.Name = "lblBirthday"
Me.lblBirthday.Size = New System.Drawing.Size(60, 17)
Me.lblBirthday.TabIndex = 68
Me.lblBirthday.Text = "出生日期:"
'
'lblAddress
'
Me.lblAddress.AutoSize = True
Me.lblAddress.Location = New System.Drawing.Point(104, 112)
Me.lblAddress.Name = "lblAddress"
Me.lblAddress.Size = New System.Drawing.Size(35, 17)
Me.lblAddress.TabIndex = 66
Me.lblAddress.Text = "地址:"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(104, 87)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(35, 17)
Me.Label1.TabIndex = 64
Me.Label1.Text = "性别:"
'
'lblName
'
Me.lblName.AutoSize = True
Me.lblName.Location = New System.Drawing.Point(104, 62)
Me.lblName.Name = "lblName"
Me.lblName.Size = New System.Drawing.Size(35, 17)
Me.lblName.TabIndex = 62
Me.lblName.Text = "姓名:"
'
'lblID
'
Me.lblID.AutoSize = True
Me.lblID.Location = New System.Drawing.Point(56, 37)
Me.lblID.Name = "lblID"
Me.lblID.Size = New System.Drawing.Size(72, 17)
Me.lblID.TabIndex = 60
Me.lblID.Text = "身份证号码:"
'
'TextBoxAddress
'
Me.TextBoxAddress.Location = New System.Drawing.Point(152, 112)
Me.TextBoxAddress.Name = "TextBoxAddress"
Me.TextBoxAddress.Size = New System.Drawing.Size(344, 21)
Me.TextBoxAddress.TabIndex = 67
Me.TextBoxAddress.Text = ""
'
'TextBoxName
'
Me.TextBoxName.Location = New System.Drawing.Point(152, 62)
Me.TextBoxName.Name = "TextBoxName"
Me.TextBoxName.TabIndex = 63
Me.TextBoxName.Text = ""
'
'TextBoxID
'
Me.TextBoxID.Location = New System.Drawing.Point(152, 37)
Me.TextBoxID.Name = "TextBoxID"
Me.TextBoxID.TabIndex = 61
Me.TextBoxID.Text = ""
'
'ComboBoxDepartment
'
Me.ComboBoxDepartment.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBoxDepartment.Location = New System.Drawing.Point(152, 187)
Me.ComboBoxDepartment.Name = "ComboBoxDepartment"
Me.ComboBoxDepartment.Size = New System.Drawing.Size(121, 20)
Me.ComboBoxDepartment.TabIndex = 82
'
'BindingDemoForm8
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(552, 408)
Me.Controls.Add(Me.ComboBoxDepartment)
Me.Controls.Add(Me.lblHeader)
Me.Controls.Add(Me.btnEnd)
Me.Controls.Add(Me.btnNext)
Me.Controls.Add(Me.btnBack)
Me.Controls.Add(Me.btnFirst)
Me.Controls.Add(Me.TextBoxPosition)
Me.Controls.Add(Me.NumericUpDownSalary)
Me.Controls.Add(Me.lblContent)
Me.Controls.Add(Me.TextBoxContent)
Me.Controls.Add(Me.DateTimePickerBirthday)
Me.Controls.Add(Me.CheckBoxGender)
Me.Controls.Add(Me.lblDepartment)
Me.Controls.Add(Me.lblSalary)
Me.Controls.Add(Me.lblBirthday)
Me.Controls.Add(Me.lblAddress)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.lblName)
Me.Controls.Add(Me.lblID)
Me.Controls.Add(Me.TextBoxAddress)
Me.Controls.Add(Me.TextBoxName)
Me.Controls.Add(Me.TextBoxID)
Me.Name = "BindingDemoForm8"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "ComboBox 控件---复杂的数据绑定"
CType(Me.NumericUpDownSalary, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub BindingDemoForm8_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
' 设定窗体的最小大小
Me.MinimumSize = New Size(512, 494)
' 建立一个连接字符串
Dim strConnection As String = "Server=(local)\NetSDK;Database=北风贸易;Integrated Security=SSPI"
' 建立一个查询命令字符串
Dim strSql As String = "SELECT 身份证号码,姓名,员工性别,家庭住址,出生日期,当前工资,部门,自我介绍 FROM 飞狐工作室"
' 建立一个数据连接
Dim myConnection As SqlConnection = _
New SqlConnection(strConnection)
' 建立一个数据适配器以便针对数据源执行 SELECT 语句来提取出要填入数据集的数据记录
Dim myAD As SqlDataAdapter = New SqlDataAdapter(strSql, myConnection)
' 将数据填入数据集
myAD.Fill(ds, "飞狐工作室")
' 将 TextBox 控件的 Text 属性绑定至数据集 ds 内的 飞狐工作室 数据表的 身份证号码 字段
TextBoxID.DataBindings.Add("Text", ds, "飞狐工作室.身份证号码")
' 将 TextBox 控件的 Text 属性绑定至数据集 ds 内的 飞狐工作室 数据表的 姓名 字段
TextBoxName.DataBindings.Add("Text", ds, "飞狐工作室.姓名")
' 将 CheckBox 控件的 Checked 属性绑定至数据集 ds 内的 飞狐工作室 数据表的 员工性别 字段
CheckBoxGender.DataBindings.Add("Checked", ds, "飞狐工作室.员工性别")
' 将 TextBox 控件的 Text 属性绑定至数据集 ds 内的 飞狐工作室 数据表的 家庭住址 字段
TextBoxAddress.DataBindings.Add("Text", ds, "飞狐工作室.家庭住址")
' 将 DateTimePicker 控件的 Value 属性绑定至数据集 ds 内的 飞狐工作室 数据表的 出生日期 字段
DateTimePickerBirthday.DataBindings.Add("Value", ds, "飞狐工作室.出生日期")
' 将 NumericUpDown 控件的 Value 属性绑定至数据集 ds 内的 飞狐工作室 数据表的 当前工资 字段
NumericUpDownSalary.DataBindings.Add("Value", ds, "飞狐工作室.当前工资")
' 将 TextBox 控件的 Text 属性绑定至数据集 ds 内的 飞狐工作室 数据表的 自我介绍 字段
TextBoxContent.DataBindings.Add("Text", ds, "飞狐工作室.自我介绍")
' 将 ComboBox 控件的数据源设定成 AllDepartments 数组
ComboBoxDepartment.DataSource = AllDepartments
' 将 DisplayMember 属性设定为 EveryDepartment 对象的 DepartmentName 属性(EveryDepartment.DepartmentName)
ComboBoxDepartment.DisplayMember = "DepartmentName"
' 设定 EveryDepartment 对象的 DepartmentName 属性值将被写入稍后所绑定的字段
ComboBoxDepartment.ValueMember = "DepartmentName"
' 将 SelectedValue 属性绑定至 飞狐工作室 数据表的 部门 字段,如这一来,
' 用户所选择的选项的 DepartmentName 属性值便会写入 飞狐工作室 数据表的 部门 字段。
ComboBoxDepartment.DataBindings.Add("SelectedValue", ds, "飞狐工作室.部门")
' 取得代表 飞狐工作室 数据表的 CurrencyManager 对象
bmFoxStudio = Me.BindingContext(ds, "飞狐工作室")
' 设定当引发 PositionChanged 事件时便执行事件处理例程 飞狐工作室_PositionChanged
AddHandler bmFoxStudio.PositionChanged, AddressOf 飞狐工作室_PositionChanged
' 设定数据记录当前位置讯息的初值
TextBoxPosition.Text = String.Format("数据记录:当前位置 {0} 总数 {1}", bmFoxStudio.Position + 1, bmFoxStudio.Count)
' 关闭对数据库的连接
myConnection.Close()
End Sub
' 更新数据记录当前位置的讯息
Protected Sub 飞狐工作室_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
TextBoxPosition.Text = String.Format("数据记录:当前位置 {0} 总数 {1}", bmFoxStudio.Position + 1, bmFoxStudio.Count)
End Sub
' 按下 第一条 按钮
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
' 将 Position 属性设定成 0
bmFoxStudio.Position = 0
End Sub
' 按下 上一条 按钮
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
If bmFoxStudio.Position > 0 Then
' 将 Position 属性递减 1
bmFoxStudio.Position -= 1
End If
End Sub
' 按下 下一条 按钮
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If bmFoxStudio.Position < bmFoxStudio.Count - 1 Then
' 将 Position 属性递增 1
bmFoxStudio.Position += 1
End If
End Sub
' 按下 最后一条 按钮
Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click
bmFoxStudio.Position = bmFoxStudio.Count - 1
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -