熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

捕捉DataGrid的雙擊事件

2022-06-13   來源: .NET編程 
<!StartFragment>Option Strict Off
Option Explicit On

Imports MicrosoftVisualBasic
Imports System
Imports SystemComponentModel
Imports SystemData
Imports SystemDrawing
Imports System<a _blank>Windows</a>Forms

Namespace <a _blank>DataGrid</a>DoubleClick
    Public Class Form
        Inherits Form
        Private WithEvents dataGrid As DataGrid
        Private WithEvents myDataSet As DataSet
        Private gridMouseDownTime As DateTime
        Private components As Container

    Public Sub New()
      MyBaseNew()
      InitializeComponent()
      gridMouseDownTime = DateTimeNow
      SetUp()

    End Sub
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

      If disposing Then
        If (Not (components) Is Nothing) Then
          componentsDispose()
        End If
      End If
      MyBaseDispose(disposing)

    End Sub
    Private Sub SetUp()
      MakeDataSet()
      dataGridSetDataBinding(myDataSet Customers)
      AddCustomDataTableStyle()
    End Sub
    Private Sub MakeDataSet()
      myDataSet = New DataSet(myDataSet)
      Dim tCust As DataTable
      tCust = New DataTable(Customers)
      Dim cCustID As DataColumn
      cCustID = New DataColumn(custID)
      Dim cCustName As DataColumn
      cCustName = New DataColumn(custName)
      Dim cCurrent As DataColumn
      cCurrent = New DataColumn(custCity)
      tCustColumnsAdd(cCustID)
      tCustColumnsAdd(cCustName)
      tCustColumnsAdd(cCurrent)
      myDataSetTablesAdd(tCust)
      Dim newRow As DataRow
      Dim i As Integer
      i =

      Do While (i < )
        newRow = tCustNewRow
        newRow(custID) = iToString()
        tCustRowsAdd(newRow)
        i = (i + )
      Loop
      tCustRows()(custName) = 【孟憲會之精彩世界】
      tCustRows()(custName) = net_lover
      tCustRows()(custName) = //<a _blank>XML</a>szluohuedu<a _blank&</a>/


      tCustRows()(custCity) = 北京
      tCustRows()(custCity) = 上海
      tCustRows()(custCity) = 河南

    End Sub
    Private Sub AddCustomDataTableStyle()

      Dim ts As DataGridTableStyle
      ts = New DataGridTableStyle()
      tsMappingName = Customers
      tsAlternatingBackColor = ColorLightGray

      Dim TextCol As DataGridTextBoxColumn
      TextCol = New DataGridTextBoxColumn()
      TextColMappingName = custID
      TextColHeaderText = 序號
      TextColWidth =

      AddHandler TextColTextBoxMouseDown New MouseEventHandler(AddressOf TextBoxMouseDownHandler)
      AddHandler TextColTextBoxDoubleClick New EventHandler(AddressOf TextBoxDoubleClickHandler)
      tsGridColumnStylesAdd(TextCol)
      TextCol = New DataGridTextBoxColumn()
      TextColMappingName = custName
      TextColHeaderText = 姓名
      TextColWidth =

      AddHandler TextColTextBoxMouseDown New MouseEventHandler(AddressOf TextBoxMouseDownHandler)
      AddHandler TextColTextBoxDoubleClick New EventHandler(AddressOf TextBoxDoubleClickHandler)
      tsGridColumnStylesAdd(TextCol)
      TextCol = New DataGridTextBoxColumn()
      TextColMappingName = custCity
      TextColHeaderText = 地址
      TextColWidth =

      AddHandler TextColTextBoxMouseDown New MouseEventHandler(AddressOf TextBoxMouseDownHandler)
      AddHandler TextColTextBoxDoubleClick New EventHandler(AddressOf TextBoxDoubleClickHandler)
      tsGridColumnStylesAdd(TextCol)
      dataGridTableStylesAdd(ts)

    End Sub
    Friend WithEvents Label As SystemWindowsFormsLabel
    Private Sub InitializeComponent()
      MedataGrid = New SystemWindowsFormsDataGrid()
      MeLabel = New SystemWindowsFormsLabel()
      CType(MedataGrid SystemComponentModelISupportInitialize)BeginInit()
      MeSuspendLayout()
     
      dataGrid
     
      MedataGridCaptionVisible = False
      MedataGridDataMember =
      MedataGridHeaderForeColor = SystemDrawingSystemColorsControlText
      MedataGridLocation = New SystemDrawingPoint( )
      MedataGridName = dataGrid
      MedataGridSize = New SystemDrawingSize( )
      MedataGridTabIndex =
     
      Label
     
      MeLabelLocation = New SystemDrawingPoint( )
      MeLabelName = Label
      MeLabelSize = New SystemDrawingSize( )
      MeLabelTabIndex =
      MeLabelTextAlign = SystemDrawingContentAlignmentMiddleCenter
     
      Form
     
      MeAutoScaleBaseSize = New SystemDrawingSize( )
      MeClientSize = New SystemDrawingSize( )
      MeControlsAddRange(New SystemWindowsFormsControl() {MeLabel MedataGrid})
      MeName = Form
      MeText = 鼠標雙擊事件的例子
      CType(MedataGrid SystemComponentModelISupportInitialize)EndInit()
      MeResumeLayout(False)

    End Sub
    <STAThread()> _
    Public Shared Sub Main()

      ApplicationRun(New Form())

    End Sub
    Private Sub TextBoxDoubleClickHandler(ByVal sender As Object ByVal e As EventArgs)

      MessageBoxShow(TrueDoubleClick)

    End Sub
    Private Sub TextBoxMouseDownHandler(ByVal sender As Object ByVal e As MouseEventArgs)

      If (DateTimeNow < gridMouseDownTimeAddMilliseconds(SystemInformationDoubleClickTime)) Then
        MessageBoxShow(GridDoubleClick + CType(sender TextBox)Text)
      End If
      LabelText = TextBoxMouseDownHandler 

    End Sub
    Private Sub dataGrid_MouseDown(ByVal sender As SystemObject _
      ByVal e As SystemWindowsFormsMouseEventArgs) Handles dataGridMouseDown

      gridMouseDownTime = DateTimeNow
      LabelText = dataGrid_MouseDown 

    End Sub

    Private Sub Label_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) _
      Handles LabelClick
      LabelText =
    End Sub

    Private Sub Form_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) _
      Handles MyBaseClick
      LabelText =
    End Sub
  End Class
End Namespace
From:http://tw.wingwit.com/Article/program/net/201311/11554.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.