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

Cargar Datagridview con datos de busqueda desde otro winform

Estas en el tema de Cargar Datagridview con datos de busqueda desde otro winform en el foro de .NET en Foros del Web. Holas espero me puedan ayudar, Estoy trabajando en el Visual Studio 2008 utiliazando vb.net y SQL server 2005. Explico la situacion primeramente: Tengo un winform(inicio.vb) ...
  #1 (permalink)  
Antiguo 24/11/2009, 12:43
 
Fecha de Ingreso: octubre-2009
Mensajes: 70
Antigüedad: 14 años, 6 meses
Puntos: 0
Pregunta Cargar Datagridview con datos de busqueda desde otro winform

Holas espero me puedan ayudar, Estoy trabajando en el Visual Studio 2008 utiliazando vb.net y SQL server 2005.
Explico la situacion primeramente:

Tengo un winform(inicio.vb) que tiene la opcion isMdi container habilitada,

esta tiene un menu con un boton con la opcion "Clientes",

al apretar este boton se abre otro Winform(menu_clientes.vb),

menu_clientes.vb tiene un DataGridView, me muestra todos los clientes que ya se encuentran registrados, esto lo hace al abrir menu_clientes.vb

menu_clientes.vb tiene un ToolStrip, en este ToolStrip tengo un boton(Buscar Cliente) que abre otro winform(consulta_cliente.vb)

consulta_cliente tiene un ComboBox donde se selecciona la opcion de busqueda y un TextBox donde ingreso el dato a buscar.

Al presionar Enter se deberia cargar o actualizar el Datagridview con los datos asociados a la busqueda realizada.
El problema es que precisamente que no hace lo que quiero.

Espero que alguien me pueda ayudar porfavor, Muchas Gracias
Dejo el codigo abajo por si es que hubiese omitido un detalle o algo.

Codigo: inicio.vb
Código vb.net:
Ver original
  1. Private Sub NavBarItem1_LinkClicked(ByVal sender As Object, ByVal e As DevExpress.XtraNavBar.NavBarLinkEventArgs) Handles NavBarItem1.LinkClicked
  2.         Dim menu_cli As New menu_clientes
  3.         menu_cli.MdiParent = Me
  4.         menu_cli.WindowState = FormWindowState.Maximized
  5.         menu_cli.Show()
  6.     End Sub

Codigo: menu_clientes.vb
Código vb.net:
Ver original
  1. Private Sub buscar_cliente_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buscar_cliente.Click
  2.         Dim ConsultaCliente As New consulta_cliente
  3.         ConsultaCliente.ShowDialog()
  4.     End Sub
  5.    
  6. 'DE ESTA MANERA CARGO EL DATAGRIDVIEW CON LOS CLIENTES ASOCIADOS A LA BUSQUEDA QUE SE REALIZO
  7.     Public Sub RecargarGrilla(ByVal valor As String, ByVal opcion As String)
  8.         Dim conexion As New SqlConnection(cadena)
  9.         Dim MiDataSet As New DataSet
  10.         Dim MiAdapter As SqlDataAdapter
  11.  
  12.         If opcion = "Rut" Then
  13.             MiAdapter = New SqlDataAdapter("SELECT cod_cli AS Codigo, rut_cli AS Rut, nombre_cli AS Nombre, fijo_cli AS Telefono, movil_cli As Celular, email_cli AS Mail FROM cliente WHERE rut_cli LIKE '%" & valor & "%'", conexion)
  14.             MiAdapter.Fill(MiDataSet)
  15.             DataGridView1.DataSource = MiDataSet.Tables(0)          
  16.         End If
  17.  
  18.         If opcion = "Nombre" Then
  19.                 MiAdapter = New SqlDataAdapter("SELECT cod_cli AS Codigo, rut_cli AS Rut, nombre_cli AS Nombre, fijo_cli AS Telefono, movil_cli As Celular, email_cli AS Mail FROM cliente WHERE nombre_cli LIKE '%" & valor & "%'", conexion)
  20.                 MiAdapter.Fill(MiDataSet)
  21.                 DataGridView1.DataSource = MiDataSet.Tables(0)
  22.         End If
  23.     End Sub

Codigo: consulta_cliente.vb
Código vb.net:
Ver original
  1. Dim OpcionRut As String = "Rut"
  2.     Dim OpcionNombre As String = "Nombre"
  3.    
  4.     Private Sub txBusqueda_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txBusqueda.KeyDown
  5.      If e.KeyCode = Keys.Enter Then
  6.             e.Handled = True
  7.  
  8.             If String.IsNullOrEmpty(txOpcion.Text) Then
  9.                 ep.SetError(txOpcion, "Ingrese Opcion de Busqueda")
  10.                 'MsgBox("Ingrese Rut")
  11.                 Exit Sub
  12.             End If
  13.             ep.Clear()
  14.  
  15.             If String.IsNullOrEmpty(txBusqueda.Text) Then
  16.                 ep.SetError(txBusqueda, "Ingrese Dato a Buscar")
  17.                 Exit Sub
  18.             End If
  19.             ep.Clear()
  20.  
  21.             'BUSQUEDA POR RUT
  22.             If txOpcion.Text = OpcionRut Then
  23.                 'AQUI LLAMO A UNA FUNCION SIMILAR A ListarDatos()
  24.                 My.Forms.menu_clientes.RecargarGrilla(txBusqueda.Text, txOpcion.Text)
  25.                 Me.Close()              
  26.             End If
  27.  
  28.             'BUSQUEDA POR NOMBRE
  29.             If txOpcion.Text = OpcionNombre Then
  30.                 Me.Close()
  31.                 My.Forms.menu_clientes.RecargarGrilla(txBusqueda.Text, txOpcion.Text)
  32.             End If          
  33.         End If
  34.     End Sub
  #2 (permalink)  
Antiguo 24/11/2009, 14:53
Avatar de eperedo  
Fecha de Ingreso: septiembre-2009
Ubicación: Perú
Mensajes: 654
Antigüedad: 14 años, 7 meses
Puntos: 16
Respuesta: Cargar Datagridview con datos de busqueda desde otro winform

Podrías hacer la llamada al método RecargaGrilla luego del ShowDialog()
Código vb.net:
Ver original
  1. Dim ConsultaCliente As New consulta_cliente
  2. ConsultaCliente.ShowDialog()
  3. RecargarGrilla(ConsultaCliente.txBusqueda.Text, ConsultaCliente.txOpcion.Text)

Y en el evento KeyDown sólo cierras el formulario
Código vb.net:
Ver original
  1. 'BUSQUEDA POR RUT
  2.             If txOpcion.Text = OpcionRut Then
  3.                 Me.Close()              
  4.             End If
  5.  
  6.             'BUSQUEDA POR NOMBRE
  7.             If txOpcion.Text = OpcionNombre Then
  8.                 Me.Close()
  9.             End If

Espero te de una idea
__________________
Eduardo Peredo
Wigoin
  #3 (permalink)  
Antiguo 24/11/2009, 23:36
 
Fecha de Ingreso: octubre-2009
Mensajes: 70
Antigüedad: 14 años, 6 meses
Puntos: 0
Pregunta Respuesta: Cargar Datagridview con datos de busqueda desde otro winform

Excelente. te pasaste! Muchas pero muchas gracias. me funciono perfecto!

Pero sabes quize utilizar lo mismo en otro winform que tengo, mira te explico:

Tengo un winform(nueva_factura.vb) en ella se encuentran los datos del cliente, y ademas un ListView que contendra los productos con sus respectivo precio y cantidad.
Para agregar una nueva linea de producto presiono el boton "Nueva Linea" y se abre otro winform(nueva_linea_producto.vb) este tiene un boton para agregar un producto a traves de otro winform, una vez seleccionado se cargaran los datos del producto en nueva_linea_producto.vb y luego ingreso la cantidad y el precio asociado al producto. Y ademas el nueva_linea_producto.vb tiene un boton guardar.

La idea es que al apretar se ingrese automaticamente el producto con sus datos respectivos al Listview. pero que nueva_linea_producto.vb no se cierre inmediatamente, sino que permita ingresar otros productos.

Por lo tanto para este caso no me funciona lo que me mencionas, por que al intentar llamar a AgregarItem(...) despues del showdialog() y que esto funcione, tendria que cerrar nueva_linea_producto.vb al apretar el boton agregar.

Espero me puedas ayudar con esto, Muchas gracias por la respuesta anterior y por responder siempre tan buena onda.

Codigo: nueva_factura.vb
Código vb.net:
Ver original
  1. Public Sub AgregarItem(ByVal id As String, ByVal cod As String, ByVal nombre As String, ByVal cantidad As String, ByVal precio As String, ByVal total As String, ByVal obs As String)
  2.         Dim item As ListViewItem
  3.         item = New ListViewItem(id)
  4.         item.SubItems.Add(cod)
  5.         item.SubItems.Add(nombre)
  6.         item.SubItems.Add(cantidad)
  7.         item.SubItems.Add(precio)
  8.         item.SubItems.Add(total)
  9.         item.SubItems.Add(obs)
  10.         ListView1.Items.Add(item)
  11.  
  12.         modificar.Show()
  13.         eliminar.Show()
  14.  
  15.         LblNeto.Text = CalculaNeto()
  16.         LblNeto.Show()
  17.  
  18.         LblIva.Text = CalculaIva()
  19.         LblIva.Show()
  20.  
  21.         LblTotal.Text = CalculaTotal()
  22.         LblTotal.Show()
  23.        
  24.     End Sub

Codigo: nueva_linea_producto.vb
Código vb.net:
Ver original
  1. Private Sub guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles guardar.Click
  2.         If String.IsNullOrEmpty(txId.Text) Then
  3.             ep.SetError(txId, "Ingrese un Producto")
  4.             Exit Sub
  5.         End If
  6.  
  7.         If String.IsNullOrEmpty(txPrecio.Text) Then
  8.             ep.SetError(txPrecio, "Ingrese un Precio")
  9.             'Exit Sub
  10.             If String.IsNullOrEmpty(txCantidad.Text) Then
  11.                 ep.SetError(txCantidad, "Ingrese una Cantidad")
  12.                 Exit Sub
  13.             End If
  14.         End If
  15.         ep.Clear()
  16.         If String.IsNullOrEmpty(txCantidad.Text) Then
  17.             ep.SetError(txCantidad, "Ingrese una Cantidad")
  18.             'Exit Sub
  19.             If String.IsNullOrEmpty(txPrecio.Text) Then
  20.                 ep.SetError(txPrecio, "Ingrese un Precio")
  21.                 Exit Sub
  22.             End If
  23.         End If
  24.  
  25.         Dim fila As Integer      
  26.         For fila = 0 To My.Forms.nueva_factura.ListView1.Items.Count - 1
  27.                 Dim codProd As String = My.Forms.nueva_factura.ListView1.Items(fila).SubItems(0).Text
  28.                 If txId.Text = codProd Then
  29.                     MessageBox.Show("Este Producto, Ya se Encuentra en la Linea de Detalle", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  30.                     Exit Sub
  31.             Next
  32.             ep.Clear()
  33.  
  34.             'AQUI ANTES LLAMABA A LA FUNCION AgregarItem(...)
  35.  
  36.             Call LimpiarTextBox(Me)
  37.         End If
  38.     End Sub
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 14:39.