📄 frmsupplyinfo.vb
字号:
End If
Me.SqlDataAdapter1.SelectCommand.CommandText = strSQL
'重新填充DataSet11
Me.SqlDataAdapter1.Fill(DataSet11)
End Sub
Private Sub frmSupplyInfo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler MyCombo.TextChanged, AddressOf Ctrls_TextChanged
'Fill ComboBox list.
Dim ts As New DataGridTableStyle
Dim aColumnTextColumn As DataGridTextBoxColumn
Dim numCols As Integer = Me.DataSet11.Tables("供货商清单").Columns.Count
Dim i As Integer
For i = 0 To numCols - 1
aColumnTextColumn = New DataGridTextBoxColumn
aColumnTextColumn.MappingName = Me.DataSet11.Tables("供货商清单").Columns(i).ColumnName
aColumnTextColumn.HeaderText = Me.DataSet11.Tables("供货商清单").Columns(i).ColumnName
aColumnTextColumn.NullText = ""
AddHandler aColumnTextColumn.TextBox.MouseDown, New MouseEventHandler(AddressOf DGDoubleClick)
AddHandler aColumnTextColumn.TextBox.DoubleClick, New EventHandler(AddressOf dgdSupplyInfo_DoubleClick)
'ctype(aColumnTextColumn.TextBox,TextBox)
aColumnTextColumn.Format = "F"
ts.GridColumnStyles.Add(aColumnTextColumn)
Next
ts.MappingName = Me.DataSet11.Tables("供货商清单").TableName
ts.AllowSorting = False
ts.AlternatingBackColor = Color.LightGray
Me.dgdSupplyInfo.TableStyles.Add(ts)
MyCombo.DropDownStyle = ComboBoxStyle.DropDownList
MyCombo.Name = "MyCombo"
MyCombo.Visible = False
MyCombo.Items.Clear()
Dim db As DataBase = New DataBase
Dim dv As DataView = db.RunSelectSQL("select 业务员号,姓名 from 业务员清单")
For i = 0 To dv.Count - 1
MyCombo.Items.Add(dv.Table.Rows(i)("姓名"))
Next
db.Dispose()
Me.SqlConnection1.ConnectionString = DataBase.sConn
'用SqlDataAdapter1填充DataSet11的供货商清单
Me.SqlDataAdapter1.Fill(Me.DataSet11, "供货商清单")
'设置dgdSupplyInfo的数据源
Me.dgdSupplyInfo.DataSource = DataSet11.Tables("供货商清单")
dgdSupplyInfo.Controls.Add(Me.MyCombo)
End Sub
Private Sub dgdSupplyInfo_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgdSupplyInfo.DoubleClick
If bClose Then
Me.Close()
End If
End Sub
Public Function SetInfo() As String
Dim sReturn As String
'获得DataGrid当前被选中的行号
Dim iRow As Integer = Me.dgdSupplyInfo.CurrentRowIndex
Dim sId, sName, sUnit As String
'获取DataGrid当前被选中的行号的供货商信息
sId = Me.DataSet11.Tables("供货商清单").Rows(iRow)("供货商号")
sName = Me.DataSet11.Tables("供货商清单").Rows(iRow)("名称")
sReturn = sId.Trim + "|" + sName.Trim + "|"
Return sReturn
End Function
Private Sub dgdSupplyInfo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgdSupplyInfo.Click
MyCombo.Visible = False
MyCombo.Width = 0
End Sub
Private Sub dgdSupplyInfo_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgdSupplyInfo.CurrentCellChanged
If dgdSupplyInfo.CurrentCell.ColumnNumber = 3 Then
MyCombo.Visible = False
MyCombo.Width = 0
MyCombo.Left = dgdSupplyInfo.GetCurrentCellBounds.Left
MyCombo.Top = dgdSupplyInfo.GetCurrentCellBounds.Top
MyCombo.Text = dgdSupplyInfo.Item(dgdSupplyInfo.CurrentCell) & ""
MyCombo.Visible = True
Else
MyCombo.Visible = False
MyCombo.Width = 0
End If
End Sub
Private Sub dgdSupplyInfo_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgdSupplyInfo.Scroll
MyCombo.Visible = False
MyCombo.Width = 0
End Sub
Private Sub Ctrls_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If dgdSupplyInfo.CurrentCell.ColumnNumber = 3 Then
MyCombo.Visible = False
If dgdSupplyInfo.Item(dgdSupplyInfo.CurrentCell) & "" = "" Then
SendKeys.Send("*")
End If
dgdSupplyInfo.Item(dgdSupplyInfo.CurrentCell) = Me.MyCombo.Text
End If
End Sub
Private Sub dgdSupplyInfo_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles dgdSupplyInfo.Paint
If dgdSupplyInfo.CurrentCell.ColumnNumber = 3 Then
MyCombo.Width = dgdSupplyInfo.GetCurrentCellBounds.Width
End If
End Sub
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
If e.Button Is Me.tbbSave Then
Dim row As Integer
row = Me.dgdSupplyInfo.CurrentCell.RowNumber
Me.dgdSupplyInfo.CurrentCell = New DataGridCell(row + 1, 0)
Try
'判断DataSet11的数据是否有变化
'即DataGrid控件上是否有数据更改或新增数据
If Me.DataSet11.HasChanges Then
'通过SqlDataAdapter1更新数据库数据
Me.SqlDataAdapter1.Update(Me.DataSet11)
Me.DataSet11.Tables("供货商清单").DefaultView.RowFilter = ""
MessageBox.Show("数据修改成功!")
Else
MessageBox.Show("无修改的数据!")
End If
Catch ex As Exception
MessageBox.Show("修改的数据出错")
End Try
ElseIf e.Button Is Me.tbbDel Then
Try
'获得DataGrid当前被选中的行号
Dim iRow = Me.dgdSupplyInfo.CurrentRowIndex
'弹出对话框让用户确认要删除记录
'如果用户确认要删除记录
If MessageBox.Show("你确认要删除此条记录吗?", "Confirm", MessageBoxButtons.YesNo) = DialogResult.Yes Then
Me.DataSet11.Tables("供货商清单").Rows(iRow).Delete()
Else
Exit Sub
End If
Try
If Me.DataSet11.HasChanges Then
'用SqlDataAdapter1更新数据库
Me.SqlDataAdapter1.Update(Me.DataSet11)
Me.DataSet11.Tables("供货商清单").DefaultView.RowFilter = ""
MessageBox.Show("数据修改成功!")
Else
MessageBox.Show("无修改的数据!")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End If
End Sub
Private Sub DGDoubleClick(ByVal sender As Object, ByVal e As MouseEventArgs)
If (DateTime.Now < gridMouseDownTime.AddMilliseconds(SystemInformation.DoubleClickTime)) Then
dgdSupplyInfo_DoubleClick(Nothing, Nothing)
End If
End Sub
Private Sub dgdSupplyInfo_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgdSupplyInfo.MouseDown
gridMouseDownTime = DateTime.Now
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -