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 originalOption Explicit
Private Sub Form_Load()
' Quitamos la columna bloqueada
GRID1.FixedCols = 0
' Decimos que hay 4 columnas y solo una linea para los titulos
GRID1.Cols = 4
GRID1.Rows = 1
' cargamos los titulos
GRID1.TextMatrix(0, 0) = "Codigo"
GRID1.TextMatrix(0, 1) = "Detalle"
GRID1.TextMatrix(0, 2) = "Precio"
GRID1.TextMatrix(0, 3) = "Unidades"
End Sub
Private Sub Agregar_Click()
' si la primera casilla de la ultima linea(row) esta vacia
' usamos esa linea para guardar los datos.
' Si esta usada creamos una linea nueva
If GRID1.TextMatrix(GRID1.Rows - 1, 1) <> "" Then GRID1.Rows = GRID1.Rows + 1
' esto es para re-utilizar la primera linea que no se puede eliminar una vez creada.
' cargamos los datos en la ultima linea del grid
GRID1.TextMatrix(GRID1.Rows - 1, 0) = Text1.Text
GRID1.TextMatrix(GRID1.Rows - 1, 1) = Text2.Text
GRID1.TextMatrix(GRID1.Rows - 1, 2) = Text3.Text
GRID1.TextMatrix(GRID1.Rows - 1, 3) = Text4.Text
' apuntamos a la nueva linea por si damos a eliminar seguidamente
GRID1.Row = GRID1.Rows - 1
End Sub
Private Sub Leer_Click()
Text1.Text = GRID1.TextMatrix(GRID1.Row, 0)
Text2.Text = GRID1.TextMatrix(GRID1.Row, 1)
Text3.Text = GRID1.TextMatrix(GRID1.Row, 2)
Text4.Text = GRID1.TextMatrix(GRID1.Row, 3)
End Sub
Private Sub Modificar_Click()
GRID1.TextMatrix(GRID1.Row, 0) = Text1.Text
GRID1.TextMatrix(GRID1.Row, 1) = Text2.Text
GRID1.TextMatrix(GRID1.Row, 2) = Text3.Text
GRID1.TextMatrix(GRID1.Row, 3) = Text4.Text
End Sub
Private Sub Borrar_Click()
If GRID1.Row > 1 Or GRID1.Rows > 2 Then
GRID1.RemoveItem GRID1.Row
Else
' si solo hay una linea no se puede eliminar,
' asi que solo se vacian sus casillas.
GRID1.TextMatrix(GRID1.Row, 0) = ""
GRID1.TextMatrix(GRID1.Row, 1) = ""
GRID1.TextMatrix(GRID1.Row, 2) = ""
GRID1.TextMatrix(GRID1.Row, 3) = ""
End If
End Sub
Es muy básico, pero igual te sirve de ayuda.