本文整理汇总了VB.NET中System.Windows.Forms.DataGridView.VirtualMode属性的典型用法代码示例。如果您正苦于以下问题:VB.NET DataGridView.VirtualMode属性的具体用法?VB.NET DataGridView.VirtualMode怎么用?VB.NET DataGridView.VirtualMode使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.DataGridView 的用法示例。
在下文中一共展示了DataGridView.VirtualMode属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: VirtualModeDemo
' 导入命名空间
Imports System.IO
Imports System.Collections.Generic
Imports System.Windows.Forms
Public Class VirtualModeDemo
Inherits System.Windows.Forms.Form
Dim WithEvents dataGridView1 As New DataGridView
Public Sub New()
MyBase.New()
Text = "DataGridView virtual-mode demo (cell-level commit scope)"
Controls.Add(dataGridView1)
dataGridView1.VirtualMode = True
dataGridView1.AllowUserToDeleteRows = False
dataGridView1.Columns.Add("Numbers", "Positive Numbers")
dataGridView1.Rows.AddCopies(0, initialSize)
End Sub
Dim newRowNeeded As Boolean
Private Sub dataGridView1_NewRowNeeded(ByVal sender As Object, _
ByVal e As DataGridViewRowEventArgs) _
Handles dataGridView1.NewRowNeeded
newRowNeeded = True
End Sub
Const initialSize As Integer = 5000000
Dim numberOfRows As Integer = initialSize
Private Sub dataGridView1_RowsAdded(ByVal sender As Object, _
ByVal e As DataGridViewRowsAddedEventArgs) _
Handles dataGridView1.RowsAdded
If newRowNeeded Then
newRowNeeded = False
numberOfRows = numberOfRows + 1
End If
End Sub
#Region "data store maintance"
Const initialValue As Integer = -1
Private Sub dataGridView1_CellValueNeeded(ByVal sender As Object, _
ByVal e As DataGridViewCellValueEventArgs) _
Handles dataGridView1.CellValueNeeded
If store.ContainsKey(e.RowIndex) Then
' Use the store if the e value has been modified
' and stored.
e.Value = store(e.RowIndex)
ElseIf newRowNeeded AndAlso e.RowIndex = numberOfRows Then
If dataGridView1.IsCurrentCellInEditMode Then
e.Value = initialValue
Else
' Show a blank value if the cursor is just resting
' on the last row.
e.Value = String.Empty
End If
Else
e.Value = e.RowIndex
End If
End Sub
Private Sub dataGridView1_CellValuePushed(ByVal sender As Object, _
ByVal e As DataGridViewCellValueEventArgs) _
Handles dataGridView1.CellValuePushed
store.Add(e.RowIndex, CInt(e.Value))
End Sub
#End Region
Dim store As System.Collections.Generic.Dictionary(Of Integer, Integer) = _
New Dictionary(Of Integer, Integer)
Private Sub dataGridView1_CellValidating(ByVal sender As Object, _
ByVal e _
As DataGridViewCellValidatingEventArgs) _
Handles dataGridView1.CellValidating
Me.dataGridView1.Rows(e.RowIndex).ErrorText = ""
Dim newInteger As Integer
' Don't try to validate the 'new row' until finished
' editing since there
' is not any point in validating its initial value.
If dataGridView1.Rows(e.RowIndex).IsNewRow Then Return
If Not Integer.TryParse(e.FormattedValue.ToString(), newInteger) _
OrElse newInteger < 0 Then
e.Cancel = True
Me.dataGridView1.Rows(e.RowIndex).ErrorText = "the value must be a non-negative integer"
End If
End Sub
<STAThreadAttribute()> _
Public Shared Sub Main()
Application.Run(New VirtualModeDemo())
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Windows.Forms,代码行数:108,代码来源:DataGridView.VirtualMode
注:本文中的System.Windows.Forms.DataGridView.VirtualMode属性示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论