你的循环改成这样,因为这将通过列循环,使他们不可见......对于我的测试,以确保公正,我加了250列,把它们藏在所有有关与此环的第二...
For i As Integer = 0 To DataGridView1.ColumnCount - 1
DataGridView1.Columns(i).Visible = False
End Sub
,如果你选择这样做,这将删除所有列...
For i As Integer = 0 To DataGridView1.ColumnCount - 1
DataGridView1.Columns.Remove(DataGridView1.Columns(0).Name)
Next
这里是另一种方式...
DataGridView1.Columns.Clear()
至于你double缓冲你的datagridview,双缓冲窗体,因为它会减少发生在该窗体上的任何闪烁。 这里有两个选择:1 - 在属性窗口中为你的窗体设置双缓冲区或2 - 初始化另一个子窗口以双缓冲它...
这里是你的窗体的双缓冲代码...直接放这个在你的类名...
Public Sub New()
MyBase.New()
MyBase.DoubleBuffered = True
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
你可以,如果你选择这样做留下上面的代码,这将有助于整体的形式和坐在其上的部件。这是我最喜欢的,虽然对于一个DataGridView,以避免任何闪烁什么那么包括滚动条...
1把这个在您的窗体的最顶端...
Imports System.Reflection
2添加到您的窗体加载...
BufferMethod.DoubleBuffered(DataGridView1, True)
3滴在你的其他类的最后这个新类(末级下面)
Public NotInheritable Class BufferMethod
Public Shared Sub DoubleBuffered(dgView As DataGridView, Setting As Boolean)
Dim dgvType As Type = dgView.[GetType]()
Dim propInfo As PropertyInfo = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance Or BindingFlags.NonPublic)
propInfo.SetValue(dgView, Setting, Nothing)
End Sub
End Class
希望你喜欢!
问候,
MrCodexer
有没有其他的事情与你没有展示的gridview相关。例如,你是否需要重新查询数据源?这可能会减慢你的回应,但只是隐藏列不应该。 – jason 2013-03-04 19:00:37
你为什么隐藏所有的列?你不能隐藏网格或解除绑定数据源吗? – Jaxedin 2013-03-05 01:38:06