yronium Level: Moderator

 Registered: 14-04-2002 Posts: 907
|
Re: Regarding FlexGrid
Hello. What help do you need?
Anyway, a sample code would be: Dim rs As ADOBD.Recordset
Dim sql As String
Dim rsRow As Long, col As Long
' build the sql instruction
sql = "SELECT * FROM MyTable"
' open the recordset
Set rs = New ADODB.Recordset
rs.Open sql, cn, adForwardOnly, adLockPessimistic, adCmdText
If Not (rs.BOF And rs.EOF) Then
' set the grid size
grdMyFlexGrid.Rows = rs.RecordCount + 1
grdMyFlexGrid.FixedRows = 1
grdMyFlexGrid.Cols = rs.Fields.Count + 1
grdMyFlexGrid.FixedCols = 1
grdMyFlexGrid.ColWidth(0) = 300
' loop the recordset
Do While Not rs.EOF
rsRow = rsRow + 1
' the ID value can be stored into the RowData property
grdMyFlexGrid.RowData(rsRow) = rs.Fields("IDField").Value
' fill the grid cells with the current record values
For col = 0 To rs.Fields.Count - 1
grdMyFlexGrid.TextMatrix(rsRow, col + 1)
Next col
rs.MoveNext
Loop
End If
' close and destroy the recordset
rs.Close
Set rs = Nothing |
Remember that a MSFlexGrid is always a read-only control, so you can't provide user the ability to directly change values into it: values can only be changed by code. In order to do it, there are some tricks by using an hidden textbox, placing it over the cell and showing it, and then passing its text to the underlying cell.
Ask more for whatever is unclear.
[Edited by yronium on 21-06-2006 at 09:59 AM GMT]
____________________________
Real Programmer can count up to 1024 on his fingers
|