给DataGrid加上右键菜单
屠恩海(SunHai)
开发工具:Microsoft Visual Studio .NET 2003
操作系统:Windows XP
用XML作为DataGrid的数据源
代码如下:
Dim fileName As String Dim MyXmlDataSet As New DataSet fileName = "sunhai.xml" MyXmlDataSet.ReadXml(fileName) Form1.DefInstance.DataGrid1.DataSource = MyXmlDataSet |
启动程序,DataTable默认是闭合的,需要手动点击展开,不胜其烦,用如下代码实现自动展开DataTable:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load |
获得在DataGrid1鼠标右击的座标
Dim rowNum, columnNum As Integer '分别是行号和列号 End If End Sub |
添加ContextMenu
在设计模式添加ContextMenu1:
Text Name
删除一行 mnuDeleteRow
插入一行 mnuInsertRow
把DataGrid1属性中的ContextMenu设为ContextMenu1。
Private Sub mnuDeleteRow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDeleteRow.Click |
Private Sub mnuInsertRow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuInsertRow.Click |
怎么在DataTable中插入列呢?请各位指教!
2004年4月27日
本文地址:http://com.8s8s.com/it/it44803.htm