VB.NET中的DataGridview的操作

  • Post author:
  • Post category:其他




VB.NET中的DataGridview的操作

这几天做了一个上位机,需要动态的修改DataGridview的行和列的内容和数据。

Public Class Form1  
  
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        
'添加行        
Me.DataGridView1.Rows.Add()    
End Sub    

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click        
'添加列        
Me.DataGridView1.Columns.Add("1", "on")    
End Sub    

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click        
'删除行        
Me.DataGridView1.Rows.RemoveAt(0)    
End Sub    

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click        
'删除列        
Me.DataGridView1.Columns.RemoveAt(0)    
End Sub

End Class

实际的案例中删除了整个DataGridview,然后重新添加了列

 Private Sub ToolStripButton3_Click(sender As Object, e As EventArgs) Handles ToolStripButton数据监控.Click
ToolStripButton传感器.ForeColor = Color.DimGray
ToolStripButton主机类.ForeColor = Color.DimGray
ToolStripButton数据监控.ForeColor = Color.Black
DataGridViewData.Columns.Clear()
DataGridViewData.Columns.Add("Columns1", "序号")
DataGridViewData.Columns.Add("Columns2", "时间")
DataGridViewData.Columns.Add("Columns3", "温度")
DataGridViewData.Columns.Add("Columns4", "湿度")
DataGridViewData.Columns.Add("Columns5", "电压")
DataGridViewData.Columns.Add("Columns6", "电流")
ViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
End Sub



版权声明:本文为lastliudexi原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。