Hej! Hej Joel! Det enda sätt som jag har sett och provat är att lägga en textbox över den cell som man vill editera och sedan kopiera in värdet från textboxen till cellen. Det går att fånga upp storlek och position på cellen så att textfältets storlek kan anpassas efter detta. Hör gärna av dig för mer info... MsFlex Grid 6.0
Undrar hur man får en FlexGrid kontroll att fungera ungefär lika som en tabell? så att man kan trycka in värden och addera rader samt visa inskriven info?
Tacksam för svar!!
//JoelSv: MsFlex Grid 6.0
Sv: MsFlex Grid 6.0
Skapa en grid med namn= Fg2
egenskaper:
Cols = 6
Rows= 20
Fillstyle= repeat
Focusrect = Heavy
Fontname 0 Arial
Fontsize = 9
Skapa en textbox med namn= txtEdit
Fontname = Arial
Fontsize = 9
Borderstyle = none
Visible = false
Kopiera nedanstående kod
Sub Form_Load()
Dim i As Integer
' Make first column narrow.
Fg2.ColWidth(0) = Fg2.ColWidth(0) / 2
Fg2.ColAlignment(0) = 1 ' Center center.
' Label rows and columns.
For i = Fg2.FixedRows To Fg2.Rows - 1
Fg2.TextArray(Fgi(i, 0)) = i
Next
For i = Fg2.FixedCols To Fg2.Cols - 1
Fg2.TextArray(Fgi(0, i)) = i
Next
' Initialize edit box (so it loads now).
txtEdit = ""
End Sub
Function Fgi(r As Integer, c As Integer) As Integer
Fgi = c + Fg2.Cols * r
End Function
Sub Fg2_KeyPress(KeyAscii As Integer)
MSHFlexGridEdit Fg2, txtEdit, KeyAscii
End Sub
Sub Fg2_DblClick()
MSHFlexGridEdit Fg2, txtEdit, 32 ' Simulate a space.
End Sub
Sub MSHFlexGridEdit(MSHFlexGrid As Control, _
Edt As Control, KeyAscii As Integer)
' Use the character that was typed.
Select Case KeyAscii
' A space means edit the current text.
Case 0 To 32
Edt = MSHFlexGrid
Edt.SelStart = 1000
' Anything else means replace the current text.
Case Else
Edt = Chr(KeyAscii)
Edt.SelStart = 1
End Select
' Show Edt at the right place.
Edt.Move MSHFlexGrid.Left + MSHFlexGrid.CellLeft, _
MSHFlexGrid.Top + MSHFlexGrid.CellTop, _
MSHFlexGrid.CellWidth - 8, _
MSHFlexGrid.CellHeight - 8
Edt.Visible = True
' And make it work.
Edt.SetFocus
End Sub
Sub txtEdit_KeyPress(KeyAscii As Integer)
' Delete returns to get rid of beep.
If KeyAscii = Asc(vbCr) Then KeyAscii = 0
End Sub
Sub txtEdit_KeyDown(KeyCode As Integer, _
Shift As Integer)
EditKeyCode Fg2, txtEdit, KeyCode, Shift
End Sub
Sub EditKeyCode(MSHFlexGrid As Control, Edt As _
Control, KeyCode As Integer, Shift As Integer)
' Standard edit control processing.
Select Case KeyCode
Case 27 ' ESC: hide, return focus to MSHFlexGrid.
Edt.Visible = False
MSHFlexGrid.SetFocus
Case 13 ' ENTER return focus to MSHFlexGrid.
MSHFlexGrid.SetFocus
Case 38 ' Up.
MSHFlexGrid.SetFocus
DoEvents
If MSHFlexGrid.Row > MSHFlexGrid.FixedRows Then
MSHFlexGrid.Row = MSHFlexGrid.Row - 1
End If
Case 40 ' Down.
MSHFlexGrid.SetFocus
DoEvents
If MSHFlexGrid.Row < MSHFlexGrid.Rows - 1 Then
MSHFlexGrid.Row = MSHFlexGrid.Row + 1
End If
End Select
End Sub
Sub Fg2_GotFocus()
If txtEdit.Visible = False Then Exit Sub
Fg2 = txtEdit
txtEdit.Visible = False
End Sub
Sub Fg2_LeaveCell()
If txtEdit.Visible = False Then Exit Sub
Fg2 = txtEdit
txtEdit.Visible = False
End Sub