电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

捕捉DataGrid的双击事件


发布日期:2023/5/29
 
<!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

上一篇:web2.0与Web1.0的区别是什么?

下一篇:总结MasterPage中的资源文件引用路径