我自己的VB应用程序的新挑战。 [英] A new challenge by my own VB application.
问题描述
你好代码项目,帮帮我这个..
我有一个datagridview1,就像这样填充form_load,
Hello code project, help me with this..
I have a datagridview1 which populates on form_load like this,
Private Sub Dashboard_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'RevelationdbDataSet.program' table. You can move, or remove it, as needed.
Me.ProgramTableAdapter.Fill(Me.RevelationdbDataSet.program)
End Sub
我有一些导航按钮,如第一页,下一页,上一页,最后一页,这样,
and I have some navigation buttons like first,next,previous,last like this,
Private Sub NEXT_click(sender As Object, e As EventArgs) Handles NEXT.Click
ProgramBindingSource.MoveNext()
Me.BindingContext(Me.RevelationdbDataSet.program).Position += 1
End Sub
Private Sub FIRST_Click(sender As Object, e As EventArgs) Handles FIRST.Click
ProgramBindingSource.MoveFirst()
Me.BindingContext(Me.RevelationdbDataSet.program).Position = 0
End Sub
Private Sub PREVIOUS_Click(sender As Object, e As EventArgs) Handles PREVIOUS.Click
ProgramBindingSource.MovePrevious()
Me.BindingContext(Me.RevelationdbDataSet.program).Position -= 1
End Sub
Private Sub LAST_Click(sender As Object, e As EventArgs) Handles LAST.Click
ProgramBindingSource.MoveLast()
Me.BindingContext(Me.RevelationdbDataSet.program).Position _
= Me.BindingContext(Me.RevelationdbDataSet.program).Count - 1
End Sub
到目前为止一切似乎都很好。
如果我使用form2添加INSERT \DELETE,这样就更新了我的datagridview1,
Everything seems to be fine till now.
If I add INSERT\DELETE something using form2 which updates my datagridview1 like this,
Private Sub updateDGV()
form1.DataGridView1.DataSource = Nothing
Dim SDA New SqlDataAdapter
Dim DS As New DataTable
Dim bsource As New BindingSource
OpenConnection()
Try
query = "SELECT * from [program]"
command = New SqlCommand(query, connection)
SDA.SelectCommand = command
SDA.Fill(ds)
bsource.DataSource = ds
Dashboard.DataGridView1.DataSource = bsource
SDA.Update(ds)
connection.Close()
Catch ex As Exception
MsgBox(ex.Message)
Finally
command.Dispose()
End Try
End Sub
哪个更新我的datagridview,但是问题现在开始....
首先,下一个,上一个和最后一个按钮不再工作...甚至不是bindnavigator ...
如何解决这个问题?
任何帮助都将是我很高兴。
我尝试了什么:
尝试改变代码,但没有运气
Which updates my datagridview very well, BUT THE PROBLEM STARTS NOW....
First, Next, Previous and Last button no longer working... not even bindingnavigator...
how to fix this ?
Any help will be greatful to me.
What I have tried:
tried changing code but no luck
推荐答案
看起来你有绑定源存储在ProgramBindingSource。
但是,在代码中,您创建了一个新的绑定源bsource
并使用它。所以数据现在来自新的绑定源,导航按钮仍然使用旧的绑定源。
而不是使用新的变量,你应该使用原始的绑定源变量。类似
It looks like you have the binding source stored inProgramBindingSource.
However, in the code you create a new binding sourcebsource
and use that. So the data is now coming from the new bindingsource and the navigation buttons are still using the old binding source.
Instead of using a new variable, you should use the original binding source variable. Something like
...
SDA.Fill(ds)
ProgramBindingSource = New BindingSource
ProgramBindingSource.DataSource = ds
Dashboard.DataGridView1.DataSource = ProgramBindingSource
...
这篇关于我自己的VB应用程序的新挑战。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!