Jump to content

Actualizar Datagridview


celsoreis
 Share

Recommended Posts

Boas tenho outra grande questão...

EU tenho um programa que é um gestor de stocks e tenho um form para inserir produtos e tenho outro que os vai listar... O meu problema é que quando acabo de inserir um novo produto o datadridview não actualiza e para ele actualizar tenho de para de correr o programa e voltar a ligar... Como faço para ele actualizar logo assim que acabo de inserir um produto

A

Link to comment
Share on other sites

Procedimento que recebe a datagrid que qeres preencher:

Public Sub carregar_mesas(ByVal DG As DataGridView)
 DG.Rows.Clear()
 query = "Select * From mesas"
 dr = executar_query_Reader(query)
 While dr.Read
	 Dim n As Integer = DG.Rows.Add()
	 DG.Rows.Item(n).Cells(0).Value = dr("ID_mesa")
	 DG.Rows.Item(n).Cells(1).Value = dr("N_lugares")
	 If dr("Ocupada") = True Then
		 DG.Rows.Item(n).Cells(2).Value = "Ocupada"
		 DG.Rows.Item(n).Cells(2).Style.ForeColor = Color.Red
	 ElseIf dr("Reservada") = True Then
		 DG.Rows.Item(n).Cells(2).Value = "Reservada"
		 DG.Rows.Item(n).Cells(2).Style.ForeColor = Color.Orange
	 Else
		 DG.Rows.Item(n).Cells(2).Value = "Disponivel"
		 DG.Rows.Item(n).Cells(2).Style.ForeColor = Color.Green
	 End If
 End While
 con.Close()
End Sub

quando queres carregar a datagrid ou depois de fazers um insert\delete\update basta chamares assim:

carregar_mesas(DG_mesas)
Edited by apocsantos
geshi
Link to comment
Share on other sites

Procedimento que recebe a datagrid que qeres preencher:

Public Sub carregar_mesas(ByVal DG As DataGridView)
 DG.Rows.Clear()
 query = "Select * From mesas"
 dr = executar_query_Reader(query)
 While dr.Read
	 Dim n As Integer = DG.Rows.Add()
	 DG.Rows.Item(n).Cells(0).Value = dr("ID_mesa")
	 DG.Rows.Item(n).Cells(1).Value = dr("N_lugares")
	 If dr("Ocupada") = True Then
		 DG.Rows.Item(n).Cells(2).Value = "Ocupada"
		 DG.Rows.Item(n).Cells(2).Style.ForeColor = Color.Red
	 ElseIf dr("Reservada") = True Then
		 DG.Rows.Item(n).Cells(2).Value = "Reservada"
		 DG.Rows.Item(n).Cells(2).Style.ForeColor = Color.Orange
	 Else
		 DG.Rows.Item(n).Cells(2).Value = "Disponivel"
		 DG.Rows.Item(n).Cells(2).Style.ForeColor = Color.Green
	 End If
 End While
 con.Close()
End Sub

Este código meto na datagridview certo ?

quando queres carregar a datagrid ou depois de fazers um insert\delete\update basta chamares assim:

carregar_mesas(DG_mesas)

e este código meto no botão adicionar certo ?

Edited by celsoreis
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.