Ver Mensaje Individual
  #10 (permalink)  
Antiguo 22/11/2009, 04:28
Avatar de pkj
pkj
 
Fecha de Ingreso: julio-2006
Ubicación: Órbita sincrónica
Mensajes: 899
Antigüedad: 18 años, 9 meses
Puntos: 29
Respuesta: Pasar datos desde un Textbox hacia un FlexGrid

Yo no había usado nunca este control, así que por curiosidad he estado experimentando un rato y he creado unos botones con código básico para hacer lo que pedias.
Te lo pongo, no para que lo uses directamente, sino por si te sirve para aclarar tus dudas.

He creado un form con un flexgrid llamado GRID1, 4 textbox (text1...text4) y 4 botones para agregar linea, eliminar linea, modificar linea y leer linea.

Código :
Ver original
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4.   ' Quitamos la columna bloqueada
  5.   GRID1.FixedCols = 0
  6.   ' Decimos que hay 4 columnas y solo una linea para los titulos
  7.   GRID1.Cols = 4
  8.   GRID1.Rows = 1
  9.   ' cargamos los titulos
  10.   GRID1.TextMatrix(0, 0) = "Codigo"
  11.   GRID1.TextMatrix(0, 1) = "Detalle"
  12.   GRID1.TextMatrix(0, 2) = "Precio"
  13.   GRID1.TextMatrix(0, 3) = "Unidades"
  14. End Sub
  15.  
  16. Private Sub Agregar_Click()
  17.   ' si la primera casilla de la ultima linea(row) esta vacia
  18.   ' usamos esa linea para guardar los datos.
  19.   ' Si esta usada creamos una linea nueva
  20.   If GRID1.TextMatrix(GRID1.Rows - 1, 1) <> "" Then GRID1.Rows = GRID1.Rows + 1
  21.   ' esto es para re-utilizar la primera linea que no se puede eliminar una vez creada.
  22.  
  23.   ' cargamos los datos en la ultima linea del grid
  24.   GRID1.TextMatrix(GRID1.Rows - 1, 0) = Text1.Text
  25.   GRID1.TextMatrix(GRID1.Rows - 1, 1) = Text2.Text
  26.   GRID1.TextMatrix(GRID1.Rows - 1, 2) = Text3.Text
  27.   GRID1.TextMatrix(GRID1.Rows - 1, 3) = Text4.Text
  28.  
  29.   ' apuntamos a la nueva linea por si damos a eliminar seguidamente
  30.   GRID1.Row = GRID1.Rows - 1
  31. End Sub
  32.  
  33. Private Sub Leer_Click()
  34.   Text1.Text = GRID1.TextMatrix(GRID1.Row, 0)
  35.   Text2.Text = GRID1.TextMatrix(GRID1.Row, 1)
  36.   Text3.Text = GRID1.TextMatrix(GRID1.Row, 2)
  37.   Text4.Text = GRID1.TextMatrix(GRID1.Row, 3)
  38. End Sub
  39.  
  40. Private Sub Modificar_Click()
  41.   GRID1.TextMatrix(GRID1.Row, 0) = Text1.Text
  42.   GRID1.TextMatrix(GRID1.Row, 1) = Text2.Text
  43.   GRID1.TextMatrix(GRID1.Row, 2) = Text3.Text
  44.   GRID1.TextMatrix(GRID1.Row, 3) = Text4.Text
  45. End Sub
  46.  
  47. Private Sub Borrar_Click()
  48.   If GRID1.Row > 1 Or GRID1.Rows > 2 Then
  49.     GRID1.RemoveItem GRID1.Row
  50.   Else
  51.   ' si solo hay una linea no se puede eliminar,
  52.   ' asi que solo se vacian sus casillas.
  53.     GRID1.TextMatrix(GRID1.Row, 0) = ""
  54.     GRID1.TextMatrix(GRID1.Row, 1) = ""
  55.     GRID1.TextMatrix(GRID1.Row, 2) = ""
  56.     GRID1.TextMatrix(GRID1.Row, 3) = ""
  57.   End If
  58. End Sub

Es muy básico, pero igual te sirve de ayuda.
__________________
No hay preguntas tontas, solo gente estup..., ¡No!, ¿como era? No hay gente que pregunte a tontos... ¡Nooo!... ¡Vaya cabeza!

Última edición por pkj; 22/11/2009 a las 05:10