|
-
May 18th, 2013, 09:23 AM
#1
Thread Starter
New Member
MSHFlexGrid edit problem: textbox won't show
I'm working on a program, which included an "editable" grid (MSHFlexGrid). I borrowed code from a VB book, which told me to superimpose a textbox whenever I click a cell.
With MSHFlexgrid1
' Cancel range selection, if any.
.RowSel = .Row
.ColSel = .Col
' Move the cell editor into place by making it one pixel smaller
' than the current cell.
txtCellEditor.Move .Left + .CellLeft, .Top + .CellTop, _
.CellWidth - ScaleX(1, vbPixels, vbTwips), _
.CellHeight - ScaleY(1, vbPixels, vbTwips)
' Transfer the contents of the current cell into the TextBox.
txtCellEditor.Text = .Text
' Move the TextBox in front of the grid.
txtCellEditor.Visible = True
txtCellEditor.ZOrder
txtCellEditor.SetFocus
' Remember current coordinates for later.
cellRow = .Row
cellCol = .Col
End With
I really don't see any problem with the code. I just don't know why the textbox (txtCellEditor) won't show whenever I invoke the click button on the grid. More surprisingly, the data I enter in the textbox is entered into the grid after the textbox loses focus. Just wondering how to make that textbox appear and let the user see what he is editing.
Hope anyone can help. Thanks in advance!!!
-
May 18th, 2013, 09:55 AM
#2
Re: MSHFlexGrid edit problem: textbox won't show
Jly
I think your ZOrder line is incomplete
Instead of .. txtCellEditor.ZOrder
,, try this ... txtCellEditor.ZOrder 0
Spoo
-
May 18th, 2013, 11:00 AM
#3
Thread Starter
New Member
Re: MSHFlexGrid edit problem: textbox won't show
Thanks for responding, Spoo.
Unfortunately specifying the ZOrder didn't work out.
Can't really seem to figure out what's wrong here.
Think you can find out other causes for this? Thanks very much.
-
May 18th, 2013, 01:50 PM
#4
Re: MSHFlexGrid edit problem: textbox won't show
Jly
I didn't try your code, but I did try this code snippet.
Code:
Private Sub FG1_Click()
'
With FG1
X1 = .CellLeft + .Left
Y1 = .CellTop + .Top
With Text1
.Left = X1
.Top = Y1
End With
End With
'
End Sub
Note that I have added this as a Click event sub.
Change the name to match your FG's name
There was no apparent need for any ZOrder 0 statement.
The TextBox just snaps to the selected FG cell.
Hope that gives you something to start with.
Spoo
-
May 18th, 2013, 09:26 PM
#5
Thread Starter
New Member
Re: MSHFlexGrid edit problem: textbox won't show
Thanks for giving time on this, Spoo.
I think the box is snapping correctly to the cell (I traced its coordinates), and probably the reason for the X-Y trace was that the *box still doesn't pop up*. (Whew.)
I don't know if it's the grid or the box or me that's the problem. I'm starting to brand this as a hopeless case, though I hope not.
Does the MSHFlexGrid need any special property setups? Or the Textbox, for that matter? Thank you, or anyone who can answer this, in advance.
-
May 18th, 2013, 10:10 PM
#6
Re: MSHFlexGrid edit problem: textbox won't show
There must be something else going on as your original code works fine for me. Can you zip the entire Project up and post it here?
-
May 18th, 2013, 11:34 PM
#7
Thread Starter
New Member
Re: MSHFlexGrid edit problem: textbox won't show
Doogle,
The grid in question is the flexSimulation MSHFlexGrid. I included everything thinking that there maybe something wrong with the project components or references as well.
PerspectiveAVS.zip
I really hope you can help me out on this. I think it'll be just a little while before I pass out. Thanks a bunch.
-
May 19th, 2013, 01:27 AM
#8
Re: MSHFlexGrid edit problem: textbox won't show
Well, I can't run your full Project as I don't have the necssary OCX or correct Crystal Reports Active X components. I did the next best thing and copied the code from the Form (and a Sub from a Module) into a new project:
Code:
Option Explicit
Private cellrow As Long
Private cellcol As Long
Private Sub flexSimulation_Click()
ShowCellEditor
End Sub
Private Sub flexSimulation_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Else
ShowCellEditor
txtCellEditor.Text = Chr$(KeyAscii)
txtCellEditor.SelStart = 1
End If
End Sub
Private Sub txtCellEditor_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
Select Case KeyAscii
Case 8
Exit Sub
Case 13
HideCellEditor
Case 27
HideCellEditor True ' Also cancel the edit.
Case Else
KeyAscii = 0
End Select
End If
End Sub
Private Sub txtCellEditor_LostFocus()
HideCellEditor
End Sub
Private Sub ShowCellEditor()
With flexSimulation
' Cancel range selection, if any.
.RowSel = .Row
.ColSel = .Col
' Move the cell editor into place by making it one pixel smaller
' than the current cell.
txtCellEditor.Move .Left + .CellLeft, .Top + .CellTop, _
.CellWidth - ScaleX(1, vbPixels, vbTwips), _
.CellHeight - ScaleY(1, vbPixels, vbTwips)
' Transfer the contents of the current cell into the TextBox.
txtCellEditor.Text = .Text
' Move the TextBox in front of the grid.
txtCellEditor.Visible = True
txtCellEditor.ZOrder 0
txtCellEditor.SetFocus
' Remember current coordinates for later.
cellrow = .Row
cellcol = .Col
End With
With txtCellEditor
Label1.Caption = .Top & ", " & .Left & ", " & .Width & ", " & .Height
End With
SelectTextboxText txtCellEditor
End Sub
Sub HideCellEditor(Optional Cancel As Boolean)
' Hide the TextBox control if necessary.
If txtCellEditor.Visible Then
' If the operation hasn't been canceled, transfer the contents
' of the TextBox into the cell that was active.
If Not Cancel Then
flexSimulation.TextMatrix(cellrow, cellcol) = txtCellEditor.Text
End If
txtCellEditor.Visible = False
End If
End Sub
Sub SelectTextboxText(pobjTextBox As TextBox)
With pobjTextBox
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
and I can't replicate you problem at all ! The TextBox moves to the correct place, accepts only numbers as input, and adds the validated input to the correct cell in the Grid when Return is pressed and / or cancels the edit if ESC is pressed.
EDIT: Found the problem. Your Form is set to ScaleMode 3 - Pixel so when you're resizing the TextBox it's not where it should be and it's not as large as you think. Simplest solution is to set the Form's ScaleMode to 1 - Twip and change
Code:
txtCellEditor.Move .Left + .CellLeft, .Top + .CellTop, _
.CellWidth - ScaleX(1, vbPixels, vbTwips), _
.CellHeight - ScaleY(1, vbPixels, vbTwips)
to
Code:
txtCellEditor.Move .Left + .CellLeft, .Top + .CellTop, _
.CellWidth - 1, _
.CellHeight - 1
The TextBox then sits pretty comfortably over the required Cell.
Last edited by Doogle; May 19th, 2013 at 02:24 AM.
-
May 19th, 2013, 06:36 AM
#9
Thread Starter
New Member
Re: MSHFlexGrid edit problem: textbox won't show
Thank goodness you managed to stop by this post.
I really didn't know the science of scaling, and how it would affect the visibility of the textbox. It's, as you said, finally sitting comfortably. I guess I just need to tweak its position so it would match the coordinates of each cell being clicked.
Again, many many thanks. You've been a huge help!
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
|