|
分類:[VB.NET/VB2005]
VB.NET2003利用します。 部分コード: //DataTable 定義
Dim aatable As New Data.DataTable Dim aarow As Data.DataRow Dim rowNum, columnNum As Integer //定义单击行列
//DataGridに入る aatable.Columns.Add("no") aatable.Columns.Add("name") aatable.Columns.Add("sex") aatable.Columns.Add("age") For i = 0 To membertable.mydataset.Tables(0).Rows.Count - 1 aarow = aatable.NewRow aarow.Item(0) = membertable.mydataset.Tables(0).Rows(i).Item("no") aarow.Item(1) = membertable.mydataset.Tables(0).Rows(i).Item("name") aarow.Item(2) = membertable.mydataset.Tables(0).Rows(i).Item("sex") aarow.Item(3) = membertable.mydataset.Tables(0).Rows(i).Item("age") aatable.Rows.Add(aarow) Me.DataGrid1.DataSource = aatable Next
//マウス右ボタンをクリック定義
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(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 End Select End If End Sub
//削除定義 Private Sub mnuDeleteRow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delete.Click Dim result As DialogResult result = MsgBox("削除よろしいですか?", MsgBoxStyle.YesNo, "注意") If result = DialogResult.Yes Then membertable.mydataset.Tables(0).Rows.RemoveAt(rowNum) aatable.Rows.RemoveAt(rowNum) membertable.mydataset.AcceptChanges() aatable.AcceptChanges() End If End Sub 今 削除時、第一行のみを削除します。DataTableのRowを得られない。マウス右ボタンをクリック定義部分は、実施できません。 どうすればいいか? よろしくお願いいたします。
|