I’m using the Flex Grid control in my program using Visual Basic 6. How can I populate and edit the data in Flex Grid?
I have 6 fields ID, Last name, First name, Middle name, Course, and Year in which all of these must be editable.
I am using DAO to an Access database.
Flex Grid control in Visual Basic
You can edit the data on the Flex Grid by extracting or passing the values of a selected cell to a text box. The whole row will be editable; if you want to exclude a certain column then you have to specify what columns to be displayed on Data Grid.
Double click the Flex Grid and follow the codes below:
Call the connection
With [Recordset]
   .MoveFirst
   .Move Fgrid.Row – 1
   txtid.Text = Fgrid.TextMatrix(Fgrid.Row, 0)
   txtLast.Text = Fgrid.TextMatrix(Fgrid.Row, 1)
   txtFirst.Text = Fgrid.TextMatrix(Fgrid.Row, 2)
   txtMiddle.Text = Fgrid.TextMatrix(Fgrid.Row, 3)
   txtCourse.Text = Fgrid.TextMatrix(Fgrid.Row, 4)
   txtpath.Text = Fgrid.TextMatrix(Fgrid.Row, 5)
End With
Â
Create a function in populating the Flex Grid.
Private Function FILLGRID()
Call the connection
With Fgrid
   Fgrid.Cols = rsstudent.Fields.Count + 1
   Fgrid.ColWidth(6) = 6
   For c = 0 To rsstudent.Fields.Count – 1
   Fgrid.TextMatrix(0, c) = rsstudent(c).Name
Next
   Fgrid.Rows = rsstudent.RecordCount + 1
   For r = 1 To rsstudent.RecordCount
   For c = 0 To rsstudent.Fields.Count – 1
   Fgrid.TextMatrix(r, c) = IIf(IsNull(rsstudent(c).Value), "(Null)", rsstudent(c).Value)
Next c
   rsstudent.MoveNext
Next r
End With
End Function