PDA

Click to See Complete Forum and Search --> : How to make flexGrid editable???


shovels
Apr 5th, 2000, 11:31 PM
Hi,

I'm using the following code to create and populate a felxgrid with information from an Access DB. Can anyone please tell me how to edit the code in order to make the Grid editable. i.e I want to be able to update the info in the Db Table from my form.

Any help or suggestions would be greatly appreciated.
cheers,
shovels

Set rs1 = New adodb.Recordset 'create recordset
rs1.Open "select * from AdministratorPasswords", conn, adOpenKeyset, adLockOptimistic 'populate rs with query result


mfgFlex1.Clear 'set grid layout at run-time
k = rs1.RecordCount
j = rs1.Fields.Count
mfgFlex1.Rows = k + 1
mfgFlex1.Cols = j + 1

With mfgFlex1
lngRow = 1
Do Until rs1.EOF
mfgFlex1.TextMatrix(0, 1) = "Username"
mfgFlex1.TextMatrix(0, 2) = "Password"
For lngCol = 0 To rs1.Fields.Count - 1
.TextMatrix(lngRow, lngCol + 1) = rs1(lngCol)
Next lngCol
rs1.MoveNext
lngRow = lngRow + 1
Loop
End With

shanzek
Apr 6th, 2000, 04:33 AM
Try this code - it allows backspaces and c/r to next cell...

'****************
Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)

'check for carriage return - move to next cell...

If Chr(KeyAscii) = Chr(13) Then
If MSHFlexGrid1.Col >= MSHFlexGrid1.Cols - 1 Then
MSHFlexGrid1.Col = 1
If MSHFlexGrid1.Row >= MSHFlexGrid1.Rows - 1 Then
MSHFlexGrid1.Row = 1
Exit Sub
Else
MSHFlexGrid1.Row = MSHFlexGrid1.Row + 1
Exit Sub

End If

Else
MSHFlexGrid1.Col = MSHFlexGrid1.Col + 1
Exit Sub
End If
End If


' handle backspace
If Chr(KeyAscii) = Chr(8) Then
MSHFlexGrid1.Text = Mid(MSHFlexGrid1.Text, 1, Len(MSHFlexGrid1.Text) - 1)
Exit Sub
End If

'other key pressed... append to existing text

MSHFlexGrid1.Text = MSHFlexGrid1.Text & Chr(KeyAscii)

End Sub

' ***************************

It works for me so far...
Steve Hanzek
shanzek@execpc.com

Devon
Apr 6th, 2000, 05:28 AM
Wow! this code is great!

I've always dropped a textbox on the flexgrid
and have the user enter values in the textbox --
but that's a real hassle and it doesn't work
if you allow the users to resize the columns/rows
of the flex grid

One thing:
When handling the backspace key I found that if a cell
is empty then you get an error (because you can't use
the MID function on an empty string)

So just code:
if MSHFlexGrid1.Text="" then exit sub

in the "handle backspace" section

Hope this doesn't insult anyone - it wasn't meant too.