Add the right-click menu 2066 [original]

zhaozj2021-02-16  59

.style1 {font-size: 24px; font-family: "书"} .style10 {font-weight: bold; font-size: 18px; color: # 0000ff} .style12 {font-size: 14px; color: # 0000ff } .Style13 {font-size: 16px} .style15 {font-size: 24px} .style16 {font-weight: bold; color: # 0000ff} .style17 {color: # 0000FF} .style18 {font-size: 36px} .Style2 {font-weight: bold; font-size: lar;, color: # 0000f} .style4 {color: # 0000FF; font-style: italic} to DataGrid plus right-click menu Tuenhai (Sunhai) Development Tools: Microsoft Visual Studio .NET 2003 operating system: Windows XP uses XML as DataGrid data source code as follows:

Dim fileName As StringDim MyXmlDataSet As New DataSetfileName = "sunhai.xml" MyXmlDataSet.ReadXml (fileName) Form1.DefInstance.DataGrid1.DataSource = MyXmlDataSet launcher, DataTable default is closed, manually click to expand, troublesome, with the following code Automatically expand DataTable:

Private Sub Form1_Load (Byval e AS Object, Byval e as system.eventargs "handles mybase.load data" Handles mybase.load DataGrid1.expand (-1) 'To expand the number of rows, set to -1 means expanded all rows DataGrid1.navigateto (0, "DataTablename ") End Sub gets the coordinate of the DataGrid1 mouse

Dim rowNum, columnNum As Integer 'are the row and column numbers Private Sub DataGrid1_MouseDown (ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown Dim myGrid As DataGrid = CType (sender, DataGrid) Dim HTI as system.windows.forms.dataGrid.hittestinfo hti = mygrid.hittest (ex, EY) if E.Button = mousebuttons.right and e.clicks = 1 TEN 'If it is right-click 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 'right click row obtained columnNum = hti. Column 'gets the mouse right click on the Live End Select End If End Sub Add ContextMenu Add ContextMenu1: Text Name Removes a line MnudeleTerow inserts a line MNUInSertrow Set the CONTEXTMENU1 in the DataGrid1 property. Private Sub Mnudeleterow_Click (Byval E AS System.EventArgs) Handles Mnudeleterow.click MyXMLDATASet.Tables (0). Rows.Removeat (Rownum) 'Delete 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) MyXMLDataSet.Acceptchange () 'does not add this sentence, you will find that the inserted row is "last" how to insert the column in DataTable? Please advise!

转载请注明原文地址:https://www.9cbs.com/read-18500.html

New Post(0)