Foros del Web » Programación para mayores de 30 ;) » .NET »

Refresh datagridview!!!!!

Estas en el tema de Refresh datagridview!!!!! en el foro de .NET en Foros del Web. Hola nuevamente aqui con otro problemita y es el siguiente: Estroy trabajando en capas En la capa presentación tengo los formularios: menuprincipal - MDI listacategoria ...
  #1 (permalink)  
Antiguo 19/06/2012, 07:19
Avatar de junior1920  
Fecha de Ingreso: noviembre-2010
Ubicación: Tumán
Mensajes: 77
Antigüedad: 13 años, 4 meses
Puntos: 1
Pregunta Refresh datagridview!!!!!

Hola nuevamente aqui con otro problemita y es el siguiente:
Estroy trabajando en capas
En la capa presentación tengo los formularios:
menuprincipal - MDI
listacategoria
Registrarcategoria
Lo que pasa es que al insertar un nuevo registro no me actualiza o no me refresca el datagridview para ver el registro insertado; acabo de ver en los foros y hay unos que utilizan
Código vb:
Ver original
  1. form.showdialog
  2. cargarlista
Pero no me parece lo mejor en fin por ahi alguna idea de como puedo lograr eso
les dejo el codigo

1*CApaAccesodatos
clase: CategoriaAD
Código vb:
Ver original
  1. Imports System.Data
  2. Imports Npgsql
  3. Imports NpgsqlTypes
  4. imports EntidadNegocio
  5. Public Class CategoriaAD
  6.     Private conn As New NpgsqlConnection
  7.     Private comando As New NpgsqlCommand
  8.     #Region "Cadena de conexion"
  9.     Public Sub New()
  10.         Dim Objconexion As New conexion
  11.         conn = Objconexion.abrir
  12.         comando.Connection=conn
  13.     End Sub
  14.     #End Region
  15.     #Region "Función convertir datos"
  16.     Private Shared Function Convertircategoria(ByVal reader As IDataReader) As CategoriaEN
  17.         Dim categoria As New CategoriaEN()
  18.         categoria.gidcat = Convert.ToInt32(reader("idcat"))
  19.         categoria.gnom_cat = lTrim(RTrim(Convert.ToString(reader("nom_cat"))))
  20.         categoria.gdesc_cat = LTrim(RTrim(Convert.ToString(reader("desc_cat"))))
  21.         Return categoria
  22.     End Function
  23.     #End Region
  24.     #Region "Función listar"
  25.     Public Function listado() As List(Of CategoriaEN)
  26.         Dim listcat As New List(Of CategoriaEN)
  27.         Dim reader As NpgsqlDataReader
  28.         Dim Objcat As CategoriaEN
  29.         Try
  30.             conn.Close()
  31.             conn.Open()
  32.             comando.CommandType=CommandType.Text
  33.             comando.CommandText="SELECT idcat,nom_cat,desc_cat FROM categoria order by nom_cat,idcat asc"
  34.             reader=comando.ExecuteReader
  35.             While reader.Read()
  36.                 listcat.Add(Convertircategoria(reader))
  37.             End While
  38.             Return listcat
  39.         Catch ex As Exception
  40.             MsgBox(ex.Message, MsgBoxStyle.Critical, ex.Source)
  41.         Finally
  42.             conn.Close()
  43.             conn.ClearAllPools
  44.         End Try
  45.     End Function
  46.     #End Region
  47.     #Region "Función insertar"
  48.     Public Sub agregar(ByVal ObjCategoriaEN As CategoriaEN)
  49.         Try
  50.         comando.CommandType=CommandType.StoredProcedure
  51.         comando.CommandText="agrega_categ"
  52.        
  53.         Dim _nom_cat As New NpgsqlParameter("_nom_cat",NpgsqlTypes.NpgsqlDbType.Varchar)
  54.         _nom_cat.Value=ObjcategoriaEN.gnom_cat
  55.         _nom_cat.Direction=ParameterDirection.Input
  56.         comando.Parameters.Add(_nom_cat)
  57.        
  58.         Dim _desc_cat As New NpgsqlParameter("_desc_cat",NpgsqlTypes.NpgsqlDbType.Text)
  59.         _desc_cat.Value=ObjCategoriaEN.gdesc_cat
  60.         _desc_cat.Direction=ParameterDirection.Input
  61.         comando.Parameters.Add(_desc_cat)
  62.         comando.ExecuteNonQuery()
  63.         Catch ex As Exception
  64.             MsgBox(ex.Message, MsgBoxStyle.Critical, ex.Source)
  65.         Finally
  66.             conn.Close()
  67.             conn.ClearAllPools
  68.         End Try
  69.     End Sub
  70.     #End Region
  71. End Class

*2.- Capa: EntidadNegocio
clase: CategoriaEN
Código vb:
Ver original
  1. Public Class CategoriaEN
  2.     Private idcat As Integer
  3.     Private nom_cat As String
  4.     Private desc_cat As String
  5.     '--------------------------
  6.     Public Property gidcat()
  7.         Get
  8.             Return idcat
  9.         End Get
  10.         Set(ByVal value)
  11.             idcat=value
  12.         End Set
  13.     End Property
  14.     '--------------------------
  15.     Public Property gnom_cat()
  16.         Get
  17.             Return nom_cat
  18.         End Get
  19.         Set(ByVal value)
  20.             nom_cat=value
  21.         End Set
  22.     End Property
  23.     '--------------------------
  24.     Public Property gdesc_cat()
  25.         Get
  26.             return desc_cat
  27.         End Get
  28.         Set(ByVal value)
  29.             desc_cat=value
  30.         End Set
  31.     End Property
  32.     '--------------------------
  33. End Class

*3.- Capa: LogicaNegocio
Clase: CategoriaLN
Código vb:
Ver original
  1. Imports AccessoDatos
  2. imports EntidadNegocio
  3. Public Class CategoriaLN
  4.     Private ObjCategoriaAD As CategoriaAD
  5.     Public Sub New()
  6.         ObjCategoriaAD=New CategoriaAD
  7.     End Sub
  8.     Public Sub agregar(ByVal ObjCategoriaEN As CategoriaEN)
  9.         ObjCategoriaAD.agregar(ObjCategoriaEN)
  10.     End Sub
  11.     Public Function listado() As List(Of CategoriaEN)
  12.         return ObjCategoriaAD.listado
  13.     End Function
  14. End Class

*4.- Capa: Presentacion
Form: listcategoria
Código vb:
Ver original
  1. Imports System.Data
  2. Imports EntidadNegocio
  3. Imports LogicaNegocio
  4. Public Partial Class listcategoria
  5.     Public Sub New()
  6.         ' The Me.InitializeComponent call is required for Windows Forms designer support.
  7.         Me.InitializeComponent()
  8.         '
  9.         ' TODO : Add constructor code after InitializeComponents
  10.         '
  11.     End Sub
  12.     Private ObjCategoriaEN As CategoriaEN
  13.     Private ObjCategoriaLN As CategoriaLN
  14.     Public Sub cargarlista()
  15.         Try
  16.             ObjCategoriaEN=New CategoriaEN
  17.             ObjCategoriaLN=New CategoriaLN
  18.             dgwlistcategoria.DataSource=Me.ObjCategoriaLN.listado
  19.        Catch ex As Exception
  20.             MsgBox(ex.Message, MsgBoxStyle.Critical, ex.Source)
  21.        End Try
  22.     End Sub
  23.     Sub ListcategoriaLoad(sender As Object, e As EventArgs)
  24.        cargarlista()
  25.     End Sub
  26.     Sub Button2Click(sender As Object, e As EventArgs)
  27.         frm_insert_cat.Show()
  28.     End Sub
  29.     Sub Button5Click(sender As Object, e As EventArgs)
  30.         cargarlista()
  31.     End Sub
  32. End Class

Form: frm_insert_cat
Código vb:
Ver original
  1. imports System.Windows.Forms
  2. Imports EntidadNegocio
  3. Imports LogicaNegocio
  4. Public Partial Class frm_insert_cat
  5.     Public Sub New()
  6.         ' The Me.InitializeComponent call is required for Windows Forms designer support.
  7.         Me.InitializeComponent()
  8.        
  9.         '
  10.         ' TODO : Add constructor code after InitializeComponents
  11.         '
  12.     End Sub
  13.     Private ObjCategoriaEN As CategoriaEN
  14.     Private ObjCategoriaLN As CategoriaLN
  15.    
  16.     Sub Button2Click(sender As Object, e As EventArgs)
  17.         me.Close()
  18.     End Sub
  19.    
  20.     Sub Button1Click(sender As Object, e As EventArgs)
  21.         Dim listcat As New listcategoria
  22.         Try
  23.             ObjCategoriaEN=New CategoriaEN
  24.             ObjCategoriaLN=New CategoriaLN
  25.             ObjCategoriaEN.gnom_cat=Ltrim(Rtrim(txtnom_cat.Text))
  26.             ObjCategoriaEN.gdesc_cat=Ltrim(Rtrim(txtdesc_cat.Text))
  27.             ObjCategoriaLN.agregar(ObjCategoriaEN)
  28.             Listcat.cargarlista()
  29.             MessageBox.Show("Se grabo correctamente")
  30.             If MessageBox.Show("¿Desea Continuar agregando registros ?","Mensaje",MessageBoxButtons.YesNo,MessageBoxIcon.Question)=Windows.Forms.DialogResult.Yes Then
  31.                 txtnom_cat.Text=""
  32.                 txtdesc_cat.Text=""
  33.                 txtnom_cat.Focus
  34.             Else
  35.                 Me.close()
  36.             End If
  37.         Catch ex As Exception
  38.             MsgBox(ex.Message, MsgBoxStyle.Critical, ex.Source)
  39.         End Try
  40.     End Sub
  41. End Class

Como veran en el form: frm_insert_cat hago un llamado a cargarlista() pero no pasa nada alguien que me pueda orientar
  #2 (permalink)  
Antiguo 19/06/2012, 08:28
Avatar de Aquaventus  
Fecha de Ingreso: junio-2010
Ubicación: Lima-Peru , En el alba de la naturaleza
Mensajes: 2.105
Antigüedad: 13 años, 9 meses
Puntos: 267
Respuesta: Refresh datagridview!!!!!

Hola junior1920, el dgwlistcategoria en tu clase listcategoria existe? Porque no lo veo declarado en ningun lado, sería ideal que en vez que hagas esto en tu clase listcategoria :
Código vb:
Ver original
  1. Public Sub cargarlista()
  2.         Try
  3.             ObjCategoriaEN=New CategoriaEN
  4.             ObjCategoriaLN=New CategoriaLN
  5.             dgwlistcategoria.DataSource=Me.ObjCategoriaLN.listado
  6.        Catch ex As Exception
  7.             MsgBox(ex.Message, MsgBoxStyle.Critical, ex.Source)
  8.        End Try
  9.     End Sub

Le hagas un return :
Código vb:
Ver original
  1. Public Sub cargarlista() As List(Of CategoriaEN)
  2.         Try
  3.             ObjCategoriaEN=New CategoriaEN
  4.             ObjCategoriaLN=New CategoriaLN
  5.             return ObjCategoriaLN.listado
  6.        Catch ex As Exception
  7.             MsgBox(ex.Message, MsgBoxStyle.Critical, ex.Source)
  8.        End Try
  9.     End Sub

y eso se lo pases a tu frm_insert_cat :
Código vb:
Ver original
  1. Sub Button1Click(sender As Object, e As EventArgs)
  2.         Dim listcat As New listcategoria
  3.         Try
  4.             ObjCategoriaEN=New CategoriaEN
  5.             ObjCategoriaLN=New CategoriaLN
  6.             ObjCategoriaEN.gnom_cat=Ltrim(Rtrim(txtnom_cat.Text))
  7.             ObjCategoriaEN.gdesc_cat=Ltrim(Rtrim(txtdesc_cat.Text))
  8.             ObjCategoriaLN.agregar(ObjCategoriaEN)
  9.             dgwlistcategoria.DataSource = Listcat.cargarlista()
  10.             MessageBox.Show("Se grabo correctamente")
  11.             If MessageBox.Show("¿Desea Continuar agregando registros ?","Mensaje",MessageBoxButtons.YesNo,MessageBoxIcon.Question)=Windows.Forms.DialogResult.Yes Then
  12.                 txtnom_cat.Text=""
  13.                 txtdesc_cat.Text=""
  14.                 txtnom_cat.Focus
  15.             Else
  16.                 Me.close()
  17.             End If
  18.         Catch ex As Exception
  19.             MsgBox(ex.Message, MsgBoxStyle.Critical, ex.Source)
  20.         End Try
  21.     End Sub
Nos Cuentas!. Saludos!.
__________________
Internet es tener todo el conocimiento global a tu disposición.
Desarrollo de Software - Ejemplos .Net
  #3 (permalink)  
Antiguo 19/06/2012, 09:47
Avatar de junior1920  
Fecha de Ingreso: noviembre-2010
Ubicación: Tumán
Mensajes: 77
Antigüedad: 13 años, 4 meses
Puntos: 1
Respuesta: Refresh datagridview!!!!!

Hola Aquaventus muchas gracias por responder con respecto al datagridview esta en el formulario listcategoria y en dicho formulario hay 3 botones: Agregar, Modificar,Eliminar
Cuando yo haga click en Agregar ó modificar se abre otro formulario donde ingreso o modifico datos pero esos datos ingresado ó modificados no se refrescan en el datagridview que esta en el formulario listcategoria.
listcategoria no es una clase es un formulario :/

Ojo que cuando doy click en agregar llama al formulario: frm_insert_cat

Última edición por junior1920; 19/06/2012 a las 10:13 Razón: agregue texto
  #4 (permalink)  
Antiguo 19/06/2012, 10:18
Avatar de Aquaventus  
Fecha de Ingreso: junio-2010
Ubicación: Lima-Peru , En el alba de la naturaleza
Mensajes: 2.105
Antigüedad: 13 años, 9 meses
Puntos: 267
Respuesta: Refresh datagridview!!!!!

Con eso ya vi cual es el error, lo que pasa es que tú creas un nuevo formulario listcategoría, y en ese formulario que crear haces el llamado del listado, mas no en el formulario verdadero. Para eso tendrás que ir a tu formulario listcategoria y en las propiedades de tu datagridview, busca uno que se llama Modifiers y colocalo en public. Luego cambiarás el llamado de tu button2 :
Código vb:
Ver original
  1. frm_insert_cat.Show()
a esto :
Código vb:
Ver original
  1. Dim dialog As New frm_insert_cat(Me)
  2. dialog.ShowDialog()
Luego cambiar el constructor de tu form frm_insert_car :
Código vb:
Ver original
  1. Dim dialog As listcategoria
  2.  
  3. Public Sub New(Dim _dialog As listcategoria)
  4.         ' The Me.InitializeComponent call is required for Windows Forms designer support.
  5.        dialog = _dialog
  6.         Me.InitializeComponent()
  7.        
  8.         '
  9.        ' TODO : Add constructor code after InitializeComponents
  10.        '
  11.    End Sub
Y finalmente lo llamas asi en el mismo formulario frm_insert_cat :
Código vb:
Ver original
  1. dialog.cargarlista()
Saludos!.
__________________
Internet es tener todo el conocimiento global a tu disposición.
Desarrollo de Software - Ejemplos .Net
  #5 (permalink)  
Antiguo 19/06/2012, 11:13
Avatar de junior1920  
Fecha de Ingreso: noviembre-2010
Ubicación: Tumán
Mensajes: 77
Antigüedad: 13 años, 4 meses
Puntos: 1
Respuesta: Refresh datagridview!!!!!

Me da error
eso lo de dialog.showdialog()
solo hace q cuando el formulario: frm_insert_cat
se cierre el cargarlista() se ejecute
ya lo habia hecho asi pero solo funca cuando se cierra
  #6 (permalink)  
Antiguo 19/06/2012, 11:18
Avatar de Aquaventus  
Fecha de Ingreso: junio-2010
Ubicación: Lima-Peru , En el alba de la naturaleza
Mensajes: 2.105
Antigüedad: 13 años, 9 meses
Puntos: 267
Respuesta: Refresh datagridview!!!!!

Hola pues a mi no me da nada de eso que mencionas... cuando hago esa llamada se refleja en el que lo invocó, sin necesidad de cerrar la ventana. Pero que error menciona?
__________________
Internet es tener todo el conocimiento global a tu disposición.
Desarrollo de Software - Ejemplos .Net
  #7 (permalink)  
Antiguo 19/06/2012, 11:23
Avatar de junior1920  
Fecha de Ingreso: noviembre-2010
Ubicación: Tumán
Mensajes: 77
Antigüedad: 13 años, 4 meses
Puntos: 1
Respuesta: Refresh datagridview!!!!!

Código vb:
Ver original
  1. Dim dialog As New frm_insert_cat(Me)
Error:
Demasiados argumentos para 'Public Sub New()'. (BC30057)

Este error es en el form:listcategoria

Otra cosa estoy usando sharpdevelop y postgres :)

Última edición por junior1920; 19/06/2012 a las 11:24 Razón: Este error es en el form:listcategoria
  #8 (permalink)  
Antiguo 19/06/2012, 11:41
Avatar de Aquaventus  
Fecha de Ingreso: junio-2010
Ubicación: Lima-Peru , En el alba de la naturaleza
Mensajes: 2.105
Antigüedad: 13 años, 9 meses
Puntos: 267
Respuesta: Refresh datagridview!!!!!

Cometí un error en esta parte... le coloqué Dim cuando deberia ser Byval :
Código vb:
Ver original
  1. Dim dialog As listcategoria
  2.  
  3. Public Sub New(Byval _dialog As listcategoria)
  4.         ' The Me.InitializeComponent call is required for Windows Forms designer support.
  5.        dialog = _dialog
  6.         Me.InitializeComponent()
  7.        
  8.         '
  9.        ' TODO : Add constructor code after InitializeComponents
  10.        '
  11.    End Sub
Ojo que la modificación del constructor se la tienes que hacer ah frm_insert_cat y la declaración del form en el listcategoria. Saludos!.
__________________
Internet es tener todo el conocimiento global a tu disposición.
Desarrollo de Software - Ejemplos .Net
  #9 (permalink)  
Antiguo 19/06/2012, 11:56
Avatar de junior1920  
Fecha de Ingreso: noviembre-2010
Ubicación: Tumán
Mensajes: 77
Antigüedad: 13 años, 4 meses
Puntos: 1
Respuesta: Refresh datagridview!!!!!

Bien funca bien; ahora cuando cierro el form: frm_insert_cat se queda pegado a de ser por la ram :$ o me equivoco
  #10 (permalink)  
Antiguo 19/06/2012, 11:59
Avatar de Aquaventus  
Fecha de Ingreso: junio-2010
Ubicación: Lima-Peru , En el alba de la naturaleza
Mensajes: 2.105
Antigüedad: 13 años, 9 meses
Puntos: 267
Respuesta: Refresh datagridview!!!!!

se queda pegado?? como es eso??
__________________
Internet es tener todo el conocimiento global a tu disposición.
Desarrollo de Software - Ejemplos .Net
  #11 (permalink)  
Antiguo 19/06/2012, 12:06
Avatar de junior1920  
Fecha de Ingreso: noviembre-2010
Ubicación: Tumán
Mensajes: 77
Antigüedad: 13 años, 4 meses
Puntos: 1
De acuerdo Respuesta: Refresh datagridview!!!!!

Entonces queda así por si alguien quiera tambien la ayuda =)

*1.- CAPA:AccessoDatos
CLASE: conexion
Código vb:
Ver original
  1. Imports Npgsql
  2. Public Class conexion
  3.     Private Server,Database,User_Id,Password As String
  4.     Public Sub New()
  5.         Try
  6.         Server=System.Configuration.ConfigurationSettings.AppSettings("Server").ToString
  7.         Database=System.Configuration.ConfigurationSettings.AppSettings("Database").ToString
  8.         User_Id=System.Configuration.ConfigurationSettings.AppSettings("User_Id").ToString
  9.         Password=System.Configuration.ConfigurationSettings.AppSettings("Password").ToString
  10.         Catch ex as Exception
  11.         MsgBox(ex.Message)
  12.         End Try
  13.     End Sub
  14.     Public Function abrir() As NpgsqlConnection
  15.     Dim cCon As String
  16.     Dim conexion As NpgsqlConnection
  17.     cCon="Server="+ Server + ";" & _
  18.          "Database="+ Database + ";" & _
  19.          "User Id="+ User_Id + ";" & _
  20.          "Password="+ Password + ";"
  21.     conexion=New NpgsqlConnection(cCon)
  22.     conexion.Open()
  23.     Return conexion
  24.     End Function
  25. End Class

CLASE:CategoriaAD

Código vb:
Ver original
  1. Imports System.Data
  2. Imports Npgsql
  3. Imports NpgsqlTypes
  4. imports EntidadNegocio
  5. Public Class CategoriaAD
  6.     Private conn As New NpgsqlConnection
  7.     Private comando As New NpgsqlCommand
  8.     #Region "Cadena de conexion"
  9.     Public Sub New()
  10.         Dim Objconexion As New conexion
  11.         conn = Objconexion.abrir
  12.         comando.Connection=conn
  13.     End Sub
  14.     #End Region
  15.     #Region "Función convertir datos"
  16.     Private Shared Function Convertircategoria(ByVal reader As IDataReader) As CategoriaEN
  17.         Dim categoria As New CategoriaEN()
  18.         categoria.gidcat = Convert.ToInt32(reader("idcat"))
  19.         categoria.gnom_cat = lTrim(RTrim(Convert.ToString(reader("nom_cat"))))
  20.         categoria.gdesc_cat = LTrim(RTrim(Convert.ToString(reader("desc_cat"))))
  21.         Return categoria
  22.     End Function
  23.     #End Region
  24.     #Region "Función listar"
  25.     Public Function listado() As List(Of CategoriaEN)
  26.         Dim listcat As New List(Of CategoriaEN)
  27.         Dim reader As NpgsqlDataReader
  28.         Dim Objcat As CategoriaEN
  29.         Try
  30.             conn.Close()
  31.             conn.Open()
  32.             comando.CommandType=CommandType.Text
  33.             comando.CommandText="SELECT idcat,nom_cat,desc_cat FROM categoria order by nom_cat,idcat asc"
  34.             reader=comando.ExecuteReader
  35.             While reader.Read()
  36.                 listcat.Add(Convertircategoria(reader))
  37.             End While
  38.             Return listcat
  39.         Catch ex As Exception
  40.             MsgBox(ex.Message, MsgBoxStyle.Critical, ex.Source)
  41.         Finally
  42.             conn.Close()
  43.             conn.ClearAllPools
  44.         End Try
  45.     End Function
  46.     #End Region
  47.     #Region "Función insertar"
  48.     Public Sub agregar(ByVal ObjCategoriaEN As CategoriaEN)
  49.         Try
  50.         comando.CommandType=CommandType.StoredProcedure
  51.         comando.CommandText="agrega_categ"
  52.        
  53.         Dim _nom_cat As New NpgsqlParameter("_nom_cat",NpgsqlTypes.NpgsqlDbType.Varchar)
  54.         _nom_cat.Value=ObjcategoriaEN.gnom_cat
  55.         _nom_cat.Direction=ParameterDirection.Input
  56.         comando.Parameters.Add(_nom_cat)
  57.        
  58.         Dim _desc_cat As New NpgsqlParameter("_desc_cat",NpgsqlTypes.NpgsqlDbType.Text)
  59.         _desc_cat.Value=ObjCategoriaEN.gdesc_cat
  60.         _desc_cat.Direction=ParameterDirection.Input
  61.         comando.Parameters.Add(_desc_cat)
  62.         comando.ExecuteNonQuery()
  63.         Catch ex As Exception
  64.             MsgBox(ex.Message, MsgBoxStyle.Critical, ex.Source)
  65.         Finally
  66.             conn.Close()
  67.             conn.ClearAllPools
  68.         End Try
  69.     End Sub
  70.     #End Region
  71. End Class

*2.-CAPA:EntidadNegocio
CLASE:CategoriaEN

Código vb:
Ver original
  1. Public Class CategoriaEN
  2.     Private idcat As Integer
  3.     Private nom_cat As String
  4.     Private desc_cat As String
  5.     '--------------------------
  6.     Public Property gidcat()
  7.         Get
  8.             Return idcat
  9.         End Get
  10.         Set(ByVal value)
  11.             idcat=value
  12.         End Set
  13.     End Property
  14.     '--------------------------
  15.     Public Property gnom_cat()
  16.         Get
  17.             Return nom_cat
  18.         End Get
  19.         Set(ByVal value)
  20.             nom_cat=value
  21.         End Set
  22.     End Property
  23.     '--------------------------
  24.     Public Property gdesc_cat()
  25.         Get
  26.             return desc_cat
  27.         End Get
  28.         Set(ByVal value)
  29.             desc_cat=value
  30.         End Set
  31.     End Property
  32.     '--------------------------
  33. End Class

*3.- CAPA: LogicaNegocio
CLASE:CategoriaLN

Código vb:
Ver original
  1. Imports AccessoDatos
  2. imports EntidadNegocio
  3. Public Class CategoriaLN
  4.     Private ObjCategoriaAD As CategoriaAD
  5.     Public Sub New()
  6.         ObjCategoriaAD=New CategoriaAD
  7.     End Sub
  8.     Public Sub agregar(ByVal ObjCategoriaEN As CategoriaEN)
  9.         ObjCategoriaAD.agregar(ObjCategoriaEN)
  10.     End Sub
  11.     Public Function listado() As List(Of CategoriaEN)
  12.         return ObjCategoriaAD.listado
  13.     End Function
  14. End Class

*4.- CAPA:Presentacion
FORMULARIO: listcategoria

Código vb:
Ver original
  1. Imports System.Data
  2. Imports EntidadNegocio
  3. Imports LogicaNegocio
  4. Public Partial Class listcategoria
  5.     Public Sub New()
  6.         ' The Me.InitializeComponent call is required for Windows Forms designer support.
  7.         Me.InitializeComponent()
  8.         '
  9.         ' TODO : Add constructor code after InitializeComponents
  10.         '
  11.     End Sub
  12.     Private ObjCategoriaEN As CategoriaEN
  13.     Private ObjCategoriaLN As CategoriaLN
  14.     Public Sub cargarlista()
  15.         Try
  16.             ObjCategoriaEN=New CategoriaEN
  17.             ObjCategoriaLN=New CategoriaLN
  18.             dgwlistcategoria.DataSource=ObjCategoriaLN.listado
  19.        Catch ex As Exception
  20.             MsgBox(ex.Message, MsgBoxStyle.Critical, ex.Source)
  21.        End Try
  22.     End Sub
  23.     Sub ListcategoriaLoad(sender As Object, e As EventArgs)
  24.         cargarlista()
  25.     End Sub
  26.     Sub Button2Click(sender As Object, e As EventArgs)
  27.         Dim dialog As frm_insert_cat
  28.         dialog= New frm_insert_cat(Me)
  29.         dialog.ShowDialog()
  30.     End Sub
  31.     Sub Button5Click(sender As Object, e As EventArgs)
  32.         cargarlista()
  33.     End Sub
  34. End Class

FORMULARIO: frm_insert_cat

Código vb:
Ver original
  1. imports System.Windows.Forms
  2. Imports EntidadNegocio
  3. Imports LogicaNegocio
  4. Public Partial Class frm_insert_cat
  5.     Dim dialog As listcategoria
  6.     Public Sub New(ByVal _dialog as listcategoria)
  7.         ' The Me.InitializeComponent call is required for Windows Forms designer support.
  8.          dialog=_dialog
  9.         Me.InitializeComponent()
  10.        
  11.         '
  12.         ' TODO : Add constructor code after InitializeComponents
  13.         '
  14.     End Sub
  15.     Private ObjCategoriaEN As CategoriaEN
  16.     Private ObjCategoriaLN As CategoriaLN
  17.    
  18.     Sub Button2Click(sender As Object, e As EventArgs)
  19.         me.Close()
  20.     End Sub
  21.    
  22.     Sub Button1Click(sender As Object, e As EventArgs)
  23.         Dim listcat As New listcategoria
  24.         Try
  25.             ObjCategoriaEN=New CategoriaEN
  26.             ObjCategoriaLN=New CategoriaLN
  27.             ObjCategoriaEN.gnom_cat=Ltrim(Rtrim(txtnom_cat.Text))
  28.             ObjCategoriaEN.gdesc_cat=Ltrim(Rtrim(txtdesc_cat.Text))
  29.             ObjCategoriaLN.agregar(ObjCategoriaEN)
  30.             dialog.cargarlista()
  31.             MessageBox.Show("Se grabo correctamente")
  32.             If MessageBox.Show("¿Desea Continuar agregando registros ?","Mensaje",MessageBoxButtons.YesNo,MessageBoxIcon.Question)=Windows.Forms.DialogResult.Yes Then
  33.                 txtnom_cat.Text=""
  34.                 txtdesc_cat.Text=""
  35.                 txtnom_cat.Focus
  36.             Else
  37.                 Me.close()
  38.             End If
  39.         Catch ex As Exception
  40.             MsgBox(ex.Message, MsgBoxStyle.Critical, ex.Source)
  41.         End Try
  42.     End Sub
  43. End Class
  #12 (permalink)  
Antiguo 19/06/2012, 12:09
Avatar de junior1920  
Fecha de Ingreso: noviembre-2010
Ubicación: Tumán
Mensajes: 77
Antigüedad: 13 años, 4 meses
Puntos: 1
Pregunta Respuesta: Refresh datagridview!!!!!

Cita:
Iniciado por Aquaventus Ver Mensaje
se queda pegado?? como es eso??
Umm puede que sea de la ram o no se pero cuando lo cierro se queda la imagen del formulario: frm_insert_cat en el formulario:listcategoria
  #13 (permalink)  
Antiguo 19/06/2012, 12:23
Avatar de junior1920  
Fecha de Ingreso: noviembre-2010
Ubicación: Tumán
Mensajes: 77
Antigüedad: 13 años, 4 meses
Puntos: 1
Respuesta: Refresh datagridview!!!!!

Asi se queda
  #14 (permalink)  
Antiguo 19/06/2012, 13:24
Avatar de Aquaventus  
Fecha de Ingreso: junio-2010
Ubicación: Lima-Peru , En el alba de la naturaleza
Mensajes: 2.105
Antigüedad: 13 años, 9 meses
Puntos: 267
Respuesta: Refresh datagridview!!!!!

a tu datagrid hazle un Update() despues del listado. Se me hace raro que te ocurra eso...
__________________
Internet es tener todo el conocimiento global a tu disposición.
Desarrollo de Software - Ejemplos .Net
  #15 (permalink)  
Antiguo 19/06/2012, 15:07
Avatar de cristiantorres  
Fecha de Ingreso: marzo-2012
Mensajes: 383
Antigüedad: 12 años, 1 mes
Puntos: 61
Respuesta: Refresh datagridview!!!!!

Lo que quieres hacer es actualizar los datos del datagriedview al insertar un registro desde otro formulario?

Porque si es así lo que deverias de hacer es detectar el cierre del formulario donde agregas el registro y luego actualizar los datos.
__________________
Visita mi Blog C#, vb.net, asp.net, sql, java y mas...
Blog Cristian Torres
  #16 (permalink)  
Antiguo 19/06/2012, 21:55
Avatar de junior1920  
Fecha de Ingreso: noviembre-2010
Ubicación: Tumán
Mensajes: 77
Antigüedad: 13 años, 4 meses
Puntos: 1
Pregunta Respuesta: Refresh datagridview!!!!!

Cita:
Iniciado por cristiantorres Ver Mensaje
Lo que quieres hacer es actualizar los datos del datagriedview al insertar un registro desde otro formulario?

Porque si es así lo que deverias de hacer es detectar el cierre del formulario donde agregas el registro y luego actualizar los datos.
Hola cristiantorres lo anterior esta bien me actualiza el datagridview la imagen muestra que el formulario frm_insert_cat queda asi como una imagen pegada no te a pasado que cuando abres un archivo y demora en cargar y abres otra ventana y la minimizas se queda pegada la imagen eso es lo que pasa cuando cierro el formulario.

Otra que tu comentas que cuando cierre o detecte el cierre del formulario suponiendo que aún no quiero salir del formulario no me va mostrar lo q ingreso...

Lo anterior corre me actualiza el registro del datagridview solo que se queda pegada la imagen del formulario frm_insert_cat cuando lo cierro

Etiquetas: refresh, sql, windows
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:54.