html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

Getting Datagrid Columns Keypress,Keyup, Keydown and other events to Fire(一个很好的东西)_.NET教程_编程技术

[ ] 已经帮助:人解决问题
datagrid
'It might be easier to read the code if you
'copied this to a text program

'After your form has a functioning datagrid and dataset,
'do the following steps.
'1) Name and declare each column as a textbox as follows

Friend WithEvents Column1 As TextBox
Friend WithEvents Column2 As TextBox

'2) Create the tablestyles.
'Here is the code microsoft gives to do just that.
'(Again I did not write this part; its copied and 'pasted from MS!!)

Private Sub AddTables(ByVal myDataGrid As DataGrid, _
                    ByVal myDataSet As DataSet)
      Dim t As DataTable
      For Each t In myDataSet.Tables
                    Dim myGridTableStyle As DataGridTableStyle = New _
                    DataGridTableStyle()
                    myGridTableStyle.MappingName = t.TableName
                    myDataGrid.TableStyles.Add(myGridTableStyle)
                    ' Note that DataGridColumnStyle objects will
                    ' be created automatically for the first DataGridTableStyle
                    ' when you add it to the GridTableStylesCollection.*/
     Next
End Sub

'3) Add the next line of code in the Form Load Event
      'Use your own variable names for the datagrid and dataset)
      AddTables(DataGrid1, DataSet1)
      'Creates the variable to identify object
      Dim TempColumn As DataGridTextBoxColumn
      'Sets the variable to the datagrid column
      TempColumn = DataGrid1.TableStyles(0).GridColumnStyles(0)
      'Set the column (textboxe actually) equal to the
      'temporary column you just created.
      Column1 = TempColumn.TextBox
      'Repeat for each column you made. Notice the next line is
      'the same as the previous except it now identifies the
      'next column (one instead of zero) and the line after
      'that is the next column you created in step 1.
      TempColumn = DataGrid1.TableStyles(0).GridColumnStyles(1)
      Column2 = TempColumn.TextBox

'4) Write the code for whatever event you want to fire. Notice
'after you declared the variables withevents then they now appear
'as a class in the drop down menu. Here is example to see the
'keypress events fire for the two columns you identified.


      Private Sub Column1_Keypress(ByVal sender As Object, _
                    ByVal e As System.Windows.Forms.KeyPressEventArgs) _
                    Handles Column1.KeyPress

                    MsgBox("You have pressed the " & e.KeyChar)

      End Sub

      Private Sub Column2_Keypress(ByVal sender As Object, _
                    ByVal e As System.Windows.Forms.KeyPressEventArgs) _
                    Handles Column2.KeyPress

                    MsgBox("You have pressed the " & e.KeyChar)

      End Sub 
WsJHTML5中文学习网 - HTML5先行者学习网
WsJHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助