I am trying to refresh a DataGridView when I update some row in other Form. I'm loading the DataGridView in the load event in this way:
Private Sub Home_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
(... Nothing important...)
Me.StockBasicoTableAdapter1.FillByOwner(Me.SctmpruebasDataSet.StockBasico, idCompany)
Catch exception As Exception
BarraEstado.Text = exception.Message
End Try
End Sub
So, when I have the data updated, I use REST to send it to my Java API and I update the data in my DB. So my problem is I don't have any idea to how I can update the DataGridView in the Home form to see the row updated.
Private Sub BtnRegularizar_Click(sender As Object, e As EventArgs) Handles BtnRegularizar.Click, MyBase.Enter
Try
(... Here I update all the data ...)
VariablesGlobales.PutRequest("http://localhost:8084/SCTM/api/UpdateBulto", bulto.ToString)
Dim _dialogSuccess As OperacionCompletada = New OperacionCompletada()
_dialogSuccess.Owner = Me
_dialogSuccess.ShowDialog()
Dim company = VariablesGlobales.usuario.Item("company")
Dim idCompany = Integer.Parse(company.Item("idCompany").ToString)
Home.StockBasicoTableAdapter1.FillByOwner(Home.SctmpruebasDataSet.StockBasico, idCompany)
Catch exception As Exception
Me.BarraEstado.Text = exception.Message()
End Try
End Sub
I used this way, Home.DataGridView1.refresh()
even both at once, without any result.
Thanks for your replies.
refresh
method has nothing to do with it, it only repaints the control.
Check the following link for details regarding refresh method:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.refresh(v=vs.110).aspx
You need to reset the datasource
of gridview
control.
Example:
Home.DataGridView1.DataSource = you_data_object
and see here how is done more elegant, Step by Step :
'Open the mountains file geodatabase feature class
Dim mountainsTable As Table = Table.OpenFileGeodatabaseTable("C:\Data\Romania.gdb", "mountains")
'Create a new TableBindingAdapter object for the mountains Table
Dim tableAdapter As TableBindingAdapter = New TableBindingAdapter(mountainsTable)
'Set the UseCodedValueDomains property to display the descriptive name for the values in any
'columns which have a CodedValueDomainDefined
tableAdapter.UseCodedValueDomains = True
'Set the UseColumnAliasNames property to display alias names in the Column headers.
tableAdapter.UseColumnAliasNames = True
'Fill the adapter with all the rows from the mountains Table
tableAdapter.Fill()
'Note that the BindingSource component and the DataGridView control would normally be
'instantiated by dragging and dropping them onto a Windows Form from the toolbox.
'Create a new BindingSource component
Dim bindingSource1 As System.Windows.Forms.BindingSource = New System.Windows.Forms.BindingSource()
'Set the DataSource to be the tableAdapter object
bindingSource1.DataSource = tableAdapter
'Create a DataGridView control
Dim dataGridView1 As System.Windows.Forms.DataGridView = New System.Windows.Forms.DataGridView()
'Set the Datasource to be the bindingSource1 object
dataGridView1.DataSource = bindingSource1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.