📄 formmain.vb
字号:
Me.lblHdrDataType.TextAlign = System.Drawing.ContentAlignment.TopRight
'
'FormMain
'
Me.ClientSize = New System.Drawing.Size(240, 295)
Me.Controls.Add(Me.panelChoice)
Me.Controls.Add(Me.panelBindingData)
Me.Controls.Add(Me.dgridProjects)
Me.Text = "Binding Info"
End Sub
#End Region
' A DataSet that will hold the Projects table
' and the Tasks table.
Private myDataSet As DataSet
Private Sub FormDataSet_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) _
Handles MyBase.Load
' Create one of our UtilData objects.
Dim dpProjects As New DisplayBindingInfo.UtilData
' Make the Project table the DataSource.
' Make the strIdent field of the currently
' select row the Text property of the DataGrid
' control.
With dgridProjects
.DataSource = dpProjects.GetProjectsDT()
.DataBindings.Clear()
.DataBindings.Add("Text", .DataSource, "strIdent")
End With
' Use a utility routine to style the
' layout of Projects in the DataGrid.
UtilGUI.AddCustomDataTableStyle(dgridProjects, "Projects")
End Sub
Private Sub Grid_MouseMove _
( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.MouseEventArgs _
) _
Handles dgridProjects.MouseMove
' If the user is not interested in
' this event, do not handle it.
If Not optMouseOver.Checked Then
Exit Sub
End If
' Tell the user what information they are seeing.
lblDatumEvent.Text = "Cell Under Mouse"
' Store the DataGrid object for early binding.
Dim dgridSender As DataGrid = sender
' Store the DataGrid's DataSource object
Dim dtabDataSource As DataTable = dgridSender.DataSource
' Use the DataSource name to retrieve
' and store the current TableStyle.
Dim dgtsCurrent _
As System.Windows.Forms.DataGridTableStyle = _
dgridSender.TableStyles(dtabDataSource.TableName)
' Use the DataGrid's HitTest method to get the
' HitTest object for this Click.
Dim httstInfo As _
System.Windows.Forms.DataGrid.HitTestInfo
With dgridSender
httstInfo = .HitTest(e.X, e.Y)
End With
' Clear the labels that are meaningful only
' if the mouse is over a data cell.
lblDatumName.Text = String.Empty
lblDatumValue.Text = String.Empty
lblDatumDataType.Text = String.Empty
With httstInfo
' Display HitTest properties in the labels
lblDatumType.Text = .Type
lblDatumRow.Text = .Row
lblDatumColumn.Text = .Column
' If the mouse is positioned over a data column...
If .Column <> -1 Then
' Obtain the DataSource's column name from
' the ColumnStyles collection of the
' current TableStyle.
Dim strColumnName As String = _
dgtsCurrent.GridColumnStyles(.Column).MappingName
lblDatumName.Text = strColumnName
' Obtain the DataSource's column's data type.
lblDatumDataType.Text = _
dtabDataSource.Rows(0).Item(strColumnName). _
GetType().ToString()
' If the mouse is positioned over a data cell...
If .Row <> -1 Then
' ETHER
' Obtain and display the cell value from
' the underlying data source object.
lblDatumValue.Text = _
dtabDataSource.Rows(.Row).Item(strColumnName)
' OR
' Obtain and display the cell value from
' the DataGrid itself.
lblDatumValue.Text = _
dgridSender.Item(.Row, .Column)
End If
End If
End With
End Sub
Private Sub Grid_CurrentCellChanged _
( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) _
Handles dgridProjects.CurrentCellChanged
' If the user is not interested in
' this event, do not handle it.
If Not optCellSelection.Checked Then
Exit Sub
End If
' Since the value of CurrentCell is set before this
' event is raised, it can be used to determine
' row and column. Hit testing is not necessary.
' Tell the user what information they are seeing.
lblDatumEvent.Text = "Current Cell"
' Store the DataGrid object for early binding.
Dim dgridSender As DataGrid = sender
' Store the DataGrid's DataSource object
Dim dtabDataSource As DataTable = dgridSender.DataSource
' Use the DataSource name to retrieve
' and store the current TableStyle.
Dim dgtsCurrent _
As System.Windows.Forms.DataGridTableStyle = _
dgridSender.TableStyles(dtabDataSource.TableName)
' Using the CurrentCell, which is always a data cell...
With dgridSender.CurrentCell
' Display HitTest properties in the labels
lblDatumType.Text = 1
lblDatumRow.Text = .RowNumber
lblDatumColumn.Text = .ColumnNumber
' Obtain the DataSource's column name from
' the ColumnStyles collection of the
' current TableStyle.
Dim strColumnName As String = _
dgtsCurrent.GridColumnStyles(.ColumnNumber). _
MappingName
lblDatumName.Text = strColumnName
' Obtain the DataSource's column's data type.
lblDatumDataType.Text = _
dtabDataSource.Rows(0).Item(strColumnName). _
GetType().ToString()
' ETHER
' Obtain and display the cell value from
' the underlying data source object.
lblDatumValue.Text = _
dtabDataSource.Rows(.RowNumber).Item(strColumnName)
' OR
' Obtain and display the cell value from
' the DataGrid itself.
lblDatumValue.Text = _
dgridSender.Item(.RowNumber, .ColumnNumber)
End With
' Display the primary key of the row; based on
' the DataBindings entry that was added
' during the Load event.
lblDatumKey.Text = dgridSender.Text
End Sub
Private Sub optAny_CheckedChanged( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) _
Handles optCellSelection.CheckedChanged, _
optMouseOver.CheckedChanged
' Clear the Labels
Me.lblDatumEvent.Text = String.Empty
Me.lblDatumType.Text = String.Empty
Me.lblDatumRow.Text = String.Empty
Me.lblDatumColumn.Text = String.Empty
Me.lblDatumName.Text = String.Empty
Me.lblDatumValue.Text = String.Empty
Me.lblDatumKey.Text = String.Empty
Me.lblDatumDataType.Text = String.Empty
Me.lblHdrKey.Visible = optCellSelection.Checked
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -