我试图通过按钮referesh,然后我删除了网格,然后一个错误出现,即使我已经使grid.ondelete假。有没有什么解决办法可以避免这个错误
谢谢
Public Class Form1
Private uService As New UserService()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Grid.ReadOnly = True
Grid.OnDelete(Of User)(Function(r, row)
Return False
End Function)
LoadData()
End Sub
Private Sub LoadData()
Dim user = uService.GetUser()
Grid.Bind(user)
End Sub
Private Sub btnrefresh_Click(sender As Object, e As EventArgs) Handles btnrefresh.Click
LoadData()
End Sub
End Class
Public Module DbContext
Public Function GetOledbConnectionString() As String
Return "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\dapperdemo.accdb;Persist Security Info=False;"
End Function
End Module
Public Class UserService
Private ReadOnly _conn As OleDbConnection
Private _connectionString As String = DbContext.GetOledbConnectionString()
Public Sub New()
_conn = New OleDbConnection(_connectionString)
End Sub
Public Function GetUser() As IEnumerable(Of User)
Dim sql = "SELECT * FROM Users"
Using _conn = New OleDbConnection(DbContext.GetOledbConnectionString())
Return _conn.Query(Of User)(sql).ToList()
End Using
End Function
End Class
End Class
'result from diagnostic tools This is a copy paste from visual studio
Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Value cannot be null.
Parameter name: key</Message><StackTrace> at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at at Kimtoo.BindingProvider.DGVBindingProvider.&lt;&gt;c__DisplayClass29_0`1.&lt;Bind&gt;b__3(Object s, DataGridViewRowCancelEventArgs e)
1条答案
按热度按时间9lowa7mx1#
所以我的解决方案是阻止或关闭来自绑定提供者的onDelete事件,即键盘Delete按钮与DataGridView按键