您现在的位置是:首页
>
html鼠标双击事件 捕捉DataGrid的双击事件
捕捉DataGrid的双击事件 lt ! StartFragme t gt O tio Strict OffO tio Ex licit O Im ort Micro oft Vi ualBa icI
捕捉DataGrid的双击事件

<! StartFragment >Option Strict OffOption Explicit On Imports Microsoft VisualBasicImports SystemImports System ComponentModelImports System DataImports System DrawingImports System <a _blank >Windows</a> FormsNamespace <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 ponents As Container Public Sub New() MyBase New() InitializeComponent() gridMouseDownTime = DateTime Now SetUp() End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If (Not (ponents) Is Nothing) Then ponents Dispose() End If End If MyBase Dispose(disposing) End Sub Private Sub SetUp() MakeDataSet() dataGrid SetDataBinding(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 ) tCust Columns Add(cCustID) tCust Columns Add(cCustName) tCust Columns Add(cCurrent) myDataSet Tables Add(tCust) Dim newRow As DataRow Dim i As Integer i = Do While (i < ) newRow = tCust NewRow newRow ( custID ) = i ToString() tCust Rows Add(newRow ) i = (i + ) Loop tCust Rows( )( custName ) = 【孟宪会之精彩世界】 tCust Rows( )( custName ) = net_lover tCust Rows( )( custName ) = //<a _blank >XML</a> sz luohuedu<a _blank &</a>/ tCust Rows( )( custCity ) = 北京 tCust Rows( )( custCity ) = 上海 tCust Rows( )( custCity ) = 河南 End Sub Private Sub AddCustomDataTableStyle() Dim ts As DataGridTableStyle ts = New DataGridTableStyle() ts MappingName = Customers ts AlternatingBackColor = Color LightGray Dim TextCol As DataGridTextBoxColumn TextCol = New DataGridTextBoxColumn() TextCol MappingName = custID TextCol HeaderText = 序号 TextCol Width = AddHandler TextCol TextBox MouseDown New MouseEventHandler(AddressOf TextBoxMouseDownHandler) AddHandler TextCol TextBox DoubleClick New EventHandler(AddressOf TextBoxDoubleClickHandler) ts GridColumnStyles Add(TextCol) TextCol = New DataGridTextBoxColumn() TextCol MappingName = custName TextCol HeaderText = 姓名 TextCol Width = AddHandler TextCol TextBox MouseDown New MouseEventHandler(AddressOf TextBoxMouseDownHandler) AddHandler TextCol TextBox DoubleClick New EventHandler(AddressOf TextBoxDoubleClickHandler) ts GridColumnStyles Add(TextCol) TextCol = New DataGridTextBoxColumn() TextCol MappingName = custCity TextCol HeaderText = 地址 TextCol Width = AddHandler TextCol TextBox MouseDown New MouseEventHandler(AddressOf TextBoxMouseDownHandler) AddHandler TextCol TextBox DoubleClick New EventHandler(AddressOf TextBoxDoubleClickHandler) ts GridColumnStyles Add(TextCol) dataGrid TableStyles Add(ts ) End Sub Friend WithEvents Label As System Windows Forms Label Private Sub InitializeComponent() Me dataGrid = New System Windows Forms DataGrid() Me Label = New System Windows Forms Label() CType(Me dataGrid System ComponentModel ISupportInitialize) BeginInit() Me SuspendLayout() dataGrid Me dataGrid CaptionVisible = False Me dataGrid DataMember = Me dataGrid HeaderForeColor = System Drawing SystemColors ControlText Me dataGrid Location = New System Drawing Point( ) Me dataGrid Name = dataGrid Me dataGrid Size = New System Drawing Size( ) Me dataGrid TabIndex = Label Me Label Location = New System Drawing Point( ) Me Label Name = Label Me Label Size = New System Drawing Size( ) Me Label TabIndex = Me Label TextAlign = System Drawing ContentAlignment MiddleCenter Form Me AutoScaleBaseSize = New System Drawing Size( ) Me ClientSize = New System Drawing Size( ) Me Controls AddRange(New System Windows Forms Control() {Me Label Me dataGrid }) Me Name = Form Me Text = 鼠标双击事件的例子 CType(Me dataGrid System ComponentModel ISupportInitialize) EndInit() Me ResumeLayout(False) End Sub <STAThread()> _ Public Shared Sub Main() Application Run(New Form ()) End Sub Private Sub TextBoxDoubleClickHandler(ByVal sender As Object ByVal e As EventArgs) MessageBox Show( TrueDoubleClick ) End Sub Private Sub TextBoxMouseDownHandler(ByVal sender As Object ByVal e As MouseEventArgs) If (DateTime Now < gridMouseDownTime AddMilliseconds(SystemInformation DoubleClickTime)) Then MessageBox Show( GridDoubleClick + CType(sender TextBox) Text) End If Label Text = TextBoxMouseDownHandler End Sub Private Sub dataGrid _MouseDown(ByVal sender As System Object _ ByVal e As System Windows Forms MouseEventArgs) Handles dataGrid MouseDown gridMouseDownTime = DateTime Now Label Text = dataGrid _MouseDown End Sub Private Sub Label _Click(ByVal sender As System Object ByVal e As System EventArgs) _ Handles Label Click Label Text = End Sub Private Sub Form _Click(ByVal sender As System Object ByVal e As System EventArgs) _ Handles MyBase Click Label Text = End Sub End ClassEnd Namespace lishixinzhi/Article/program/net/201311/11554
很赞哦! (1051)