|
-
Aug 2nd, 2000, 09:43 AM
#1
Thread Starter
Evil Genius
I have a project which on the form_load event imports 2 columns of data from an access 97 database into my 2 column flexgrid control on my form.
I am using VB6 learning Edition & my question is, HOW CAN I EDIT / MODIFY THE DATA ????
I can click in one of the flexgrid cells & highlight it, and even though the enabled property is true, I cannot change any entries.
I would be very grateful for any pointers / help with this one.
Thanks everyone!
Alex Read
-
Aug 2nd, 2000, 10:04 AM
#2
Unfortunately it's not straightforward, but this MS Knowledgebase article explains how to do it.
http://support.microsoft.com/support.../Q241/3/55.ASP
-
Aug 2nd, 2000, 10:30 AM
#3
Fanatic Member
Create a grid call GRID and a text box called edit
paste this code
Private Sub edit_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
KeyAscii = 0
grid.TextMatrix(grid.Row, grid.Col) = edit
edit.Visible = False
grid.SetFocus
End Sub
Private Sub edit_LostFocus()
edit.Visible = False
End Sub
Private Sub grid_Click()
edit.Visible = False
edit.Left = grid.Left + grid.CellLeft + 20
edit.Top = grid.Top + grid.CellTop
edit.Width = grid.CellWidth
edit.Height = grid.CellHeight
edit.Text = grid.TextMatrix(grid.Row, grid.Col)
edit.Visible = True
edit.SetFocus
End Sub
Private Sub grid_Scroll()
edit.Visible = False
End Sub
Kurt Simons
[I know I'm a hack but my clients don't!]
-
Aug 2nd, 2000, 11:11 AM
#4
Thread Starter
Evil Genius
Wowsers!
Thank you all for your views! Have managed to get this to work now because of them (although why you cannot just click in the cell & type I do not know!)
The next question with regards to this is a bit harder.
Mission:
I now have the 2 flexgrid columns linked to the 2 columns from the access 97 database.
The user can edit these fields, & I need them to be able to click a button & that will update the corresponding entries within the access database.
(I hope this is not as hard as the rest of the flexgrid options I have looked at!).
Failed Attempt:
1 database set up(Db), 1 recordsets Rs (imaginatively!)....
Do While Not Rs.EOF
If Rs!Column1 <> FlxGrd.Text Then
Rs.Edit
Rs2!Column1 = FlxGrd.col
End If
Rs.MoveNext
Loop
Now then, I think this is wrong in 2 places, but just cannot work out what to use. FlxGrd (My FlexGrid control).text should be the flexgrid cell linked to
the corresponding entry in the database - is this right?
FlxGrd.Col I have placed several options here, this should be the actual column cell being analyzed (as if you did Rs!column1 on a database recordset), no matter what I try, Vb does not like it!
Oh, a third one too, I think I should be moving down a flexgrid cell after each time, notice I have put in the Rs.movenext - does the flexgrid have any options like this?
Your Help has been and will be greatly appriciated, ANY slight pointers which could help me along will be magnificent.
Thank you everyone!
Alex Read
-
Aug 2nd, 2000, 12:00 PM
#5
Fanatic Member
Dim db As Database
Dim rs As Recordset
Private Sub edit_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
KeyAscii = 0
rs.edit
rs.Fields(grid.Col) = edit
rs.Update
grid.TextMatrix(grid.Row, grid.Col) = edit
edit.Visible = False
grid.SetFocus
End Sub
Private Sub edit_LostFocus()
edit.Visible = False
End Sub
Private Sub Form_Load()
Set db = DBEngine.OpenDatabase("c:\mydatabase.mdb")
grid.Cols = 3
grid.Rows = 0
Set rs = db.OpenRecordset("select * from mytablename")
Do Until rs.EOF
grid.AddItem ""
grid.TextMatrix(grid.Rows - 1, 0) = rs.Fields(0)
grid.TextMatrix(grid.Rows - 1, 1) = rs.Fields(1)
grid.TextMatrix(grid.Rows - 1, 2) = rs.Fields(2)
rs.MoveNext
Loop
End Sub
Private Sub grid_Click()
edit.Visible = False
' move recordset to where you re at probally won't want to do it this way
rs.AbsolutePosition = grid.Row
edit.Left = grid.Left + grid.CellLeft + 20
edit.Top = grid.Top + grid.CellTop
edit.Width = grid.CellWidth
edit.Height = grid.CellHeight
edit.Text = grid.TextMatrix(grid.Row, grid.Col)
edit.Visible = True
edit.SetFocus
End Sub
Private Sub grid_Scroll()
edit.Visible = False
End Sub
Kurt Simons
[I know I'm a hack but my clients don't!]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|