celsoreis Posted May 3, 2015 at 11:34 PM Report Share #582416 Posted May 3, 2015 at 11:34 PM 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 More sharing options...
Retsu9 Posted May 4, 2015 at 06:43 PM Report Share #582457 Posted May 4, 2015 at 06:43 PM tenta Datagrid.Refresh() se nao der, crias um procedimento para listar os dados e cada vez que editas/inseres um novo registo chamas esse procedimento Link to comment Share on other sites More sharing options...
celsoreis Posted May 5, 2015 at 11:43 PM Author Report Share #582549 Posted May 5, 2015 at 11:43 PM Crio esse procedimento dentro do datagridview ou no botão que clico para adicionar ? Link to comment Share on other sites More sharing options...
Retsu9 Posted May 6, 2015 at 02:10 PM Report Share #582594 Posted May 6, 2015 at 02:10 PM (edited) 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 May 6, 2015 at 03:29 PM by apocsantos geshi Link to comment Share on other sites More sharing options...
celsoreis Posted May 6, 2015 at 06:06 PM Author Report Share #582623 Posted May 6, 2015 at 06:06 PM (edited) 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 May 6, 2015 at 09:52 PM by celsoreis Link to comment Share on other sites More sharing options...
Retsu9 Posted May 6, 2015 at 11:57 PM Report Share #582650 Posted May 6, 2015 at 11:57 PM tens um botao adicionar, dentro dele fazes tudo o que tens para fazer...insert into ... isso tudo no fim depois do registo inserido fazes isso sim Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now