首页 > 开发 > 综合 > 正文

Getting Datagrid Columns Keypress,Keyup, Keydown a

2024-07-21 02:16:54
字体:
来源:转载
供稿:网友
'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 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表