Right-click the DataGrid and choose 2066 [original].

Source: Internet
Author: User

Right-click the DataGrid and choose

     

         Tu Enhai (Sunhai)

Development Tool: Microsoft Visual Studio. NET 2003
Operating System: Windows XP

Use XML as the data source of the DataGrid

The Code is as follows:

Dim filename as string
Dim myxmldataset as new dataset
Filename = "sunhai. xml"
Myxmldataset. readxml (filename)
Form1.definstance. datagrid1.datasource = myxmldataset

Start the program. The datatable is closed by default. You need to manually click to expand the datatable. Use the following code to automatically expand the datatable:

Private sub form1_load (byval sender as object, byval e as system. eventargs) handles mybase. Load

Datagrid1.expand (-1) 'indicates the number of rows to be expanded. If it is set to-1, all rows are expanded.
Datagrid1.navigateto (0, "datatablename ")

End sub

   

  
Obtain the coordinates of the right-click on the datagrid1

Dim rownum and columnnum as integer are row numbers and column numbers respectively.
Private sub maid (byval sender as object, byval e as system. Windows. Forms. mouseeventargs) handles maid

Dim mygrid as DataGrid = ctype (sender, DataGrid)
Dim HTI as system. Windows. Forms. DataGrid. hittestinfo
HTI = mygrid. hittest (E. X, E. Y)

If E. Button = mousebuttons. Right and E. clicks = 1 then'
Select case HTI. Type'
Case System. Windows. Forms. DataGrid. hittesttype. Cell, system. Windows. Forms. DataGrid. hittesttype. rowheader, system. Windows. Forms. DataGrid. hittesttype. columnheader

Rownum = HTI. row'
Columnnum = HTI. Column '. Right-click the column
End select

End if

End sub

                 

Add contextmenu

Add contextmenu1 in design mode:
Text name
Delete a line of mnudeleterow
Insert a line of mnuinsertrow

Set contextmenu in the datagrid1 attribute to contextmenu1.

Private sub mnudeleterow_click (byval sender as system. Object, byval e as system. eventargs) handles mnudeleterow. Click

Myxmldataset. Tables (0). Rows. removeat (rownum) 'delete a row

End sub

 

Private sub mnuinsertrow_click (byval sender as system. Object, byval e as system. eventargs) handles mnuinsertrow. Click

Dim row1 as datarow = myxmldataset. Tables (0). newrow
Myxmldataset. Tables (0). Rows. insertat (row1, rownum)
If myxmldataset. acceptchanges () 'is not added, you will find that all the inserted rows are "last ".

End sub

 
How to insert columns in datatable?Please advise!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.