DataGridView如何在VB.NET中填充事件后保持选定行的位置。
我想在不使用bindingsource的情况下是否可以应用请指导。
对于数据库信息,该表没有ID,但有4列主键,即:CODEPRODUCT、BARCODE、COLORCODE、SIZE
谢谢
Private WithEvents dt As New DataTable
Dim dataAdapter As OleDbDataAdapter
Dim GetConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\demo.accdb;Persist Security Info=False;"
Private Sub population()
Try
dt = New DataTable
Dim query As String = "SELECT * from stocks"
Using con As OleDbConnection = New OleDbConnection(GetConnectionString)
Using cmd As OleDbCommand = New OleDbCommand(query, con)
Using da As New OleDbDataAdapter(cmd)
'Dim dt As DataTable = New DataTable()
da.Fill(dt)
da.Dispose()
DataGridView1.DataSource = dt
Me.DataGridView1.Refresh()
End Using
End Using
End Using
Catch ex As Exception
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
Me.DataGridView1.MultiSelect = False
population()
End Sub
Private Sub Btnrefresh_Click(sender As Object, e As EventArgs) Handles Btnrefresh.Click
population()
End Sub
结果在datagridview 19082023中
1条答案
按热度按时间z8dt9xmd1#
我们感谢他们为我们提供了最好的解决方案
根据@RezaAghaei的解决方案,这里是a link!
根据@R.Akhlaghi的解决方案,这里是a link!
我尝试了他们的代码组合,终于得到了解决方案。