Attempt to manage EZGrid column sizes

Started by Dwight Scoles, September 19, 2006, 01:06:49 AM

Previous topic - Next topic

Dwight Scoles

This is my first attempt to use FireFly or EZGrid, so whatever I'm missing will be something rudimentary, I'm sure.

My first task is to define exact column widths in my grid(s).  The grids display fine in the application and contain the column headings I've set in the Caption property for the EZGrid control.

However, my attempt to change the column size at run time is not working.  I have added code in WM_CREATE as folows:

  PostMessage hWndForm, %MSG_PREPARE_GRIDS, 0, 0
  PostMessage hWndForm, %MSG_DISPLAY_FORMS, 0, 0
(see previous post related to the purpose of %MSG_DISPLAY_FORMS]


Then, I have added a case statement included here:


Function MDIFORM_CUSTOM ( _
                       hWndForm      As Dword, _  ' handle of Form
                       wMsg          As Long,  _  ' type of message
                       wParam        As Dword, _  ' first message parameter
                       lParam        As Long   _  ' second message parameter
                       ) As Long

Local hwndwindow As Dword    

  Select Case wMsg
  Case %MSG_DISPLAY_FORMS
frmRulesEntry_Show( HWND_MDIFORM_MDICLIENT, %FALSE )
frmTables_Show( HWND_MDIFORM_MDICLIENT, %FALSE )  
  Case %MSG_PREPARE_GRIDS  
    SendMessage HWND_FRMRULESENTRY_EGSTUCKTO, %EG_SETCOLSIZE, 1, 250    
    SendMessage HWND_FRMRULESENTRY_EGSTUCKTO, %EG_SETCOLSIZE, 2, 190  
    SendMessage HWND_FRMRULESENTRY_EGSTUCKTO, %EG_REFRESHALL, 0, 0
                 MsgBox "AT PREPARE GRIDS",%MB_OK,"RAN IT"
  End Select

End Function


The MsgBox opens after the forms display (surprise to me, I had to post the message to open the forms after posting the message to prepare the grid).  The message box is just there to validate that the code segment is executed.

Result, my grid columns remain the same size no matter what value I place in the message to %EG_SETCOLSIZE.

I've attempted this with the GridMode property set to Design Mode and to Full Line Mode with no difference in operation.

Any clues as to where I should begin looking?

BTW, the LockHorzSizes property is set to False and the LockVertSizes is set to True for this grid.  I WANT to lock both but thought having LockHorzSizes to True was causing my problem so I changed it to False.

Thanks in advance for any help on this issue! :-)
Dwight

Elias Montoya

Is HWND_FRMRULESENTRY_EGSTUCKTO the handle of Egrid32?
Firefly usually names Egrid32 handles like HWND_FORM1_EGRID321 or something like that, unless you changed the name, in that case, make sure the handle belongs to the correct grid.

You can use the command EG_ISVALIDEGRIDHANDLE to see if the
provided handle is valid.

Do you have other code after this one?

Most likely i will be able tio fix this in a minute if i see more code... :)

:)

Elias Montoya

Now that i look at the code again... it will fail if you send the commands
before the grids are created...

If you are first preparing the grids, and then calling the forms
frmRulesEntry_Show( HWND_MDIFORM_MDICLIENT, %FALSE )
frmTables_Show( HWND_MDIFORM_MDICLIENT, %FALSE )


Then it means that the grids doesnt exist yet...

Are the grids inside that MDI forms? if so, then first create the forms,
then initialize the grid (Egrid32 cant process commands before being created).

:)

Dwight Scoles

Thank you Elias,

Your pointer was exactly what I needed...

I moved the:
QuotePostMessage hWndForm, %MSG_PREPARE_GRIDS, 0, 0
to become the last line in the %MSG_DISPLAY_FORMS case section of code.  It was a timing issue as you identified.

I think I'm starting to see the light... I just hope it is not a train coming down the track!  :)

Dwight

TechSupport

Quote from: Dwight ScolesI just hope it is not a train coming down the track!  :)
Don't worry, we all got hit by that train at some point in our Windows programming journey. :D  Windows is so deep and vast that sometimes it is easy to get lost.

Dwight Scoles

Hey... I appreciate all of the recommendations.  The shell of this application is starting to look real.

Two questions on grid functionality...

1) Each of the grids on my forms displays one of the cells (1,1) with a dark line around it as though it is selected.  Is it possible to not have this darker border around any of the cells until the user actually clicks in the grid?

2)  It does not see possible to edit the cell contents but only to replace the contents by retyping something new.  Any time the user clicks on a cell that holds contents, I want to put them into edit mode. What technique can be used so that when a user clicks on a cell that the cursor is immediately put into edit mode at the first character of the data inside that cell?

Thanks for all of the help.  I can see how this could actally get  to be "fun" some day!  :D

Dwight

Elias Montoya

For the 2nd one you can use this code:

'------------------------------------------------------------------------------------------------------------------------
Function FORM1_EGRID321_EGN_CELLLEFTCLICK (ControlIndex As Dword, HwndForm As Dword, hEGrid As Long, wParam As Dword, lParam As Long) As Long

Local EGN As EgridNotify Ptr

EGN = lParam

SendMessage(hEgrid, %EG_MOVECURSOR, @EGN.CELL.X, @EGN.CELL.Y)
SendMessage(hEgrid, %EG_OPENEDITION, @EGN.CELL.X, @EGN.CELL.Y)
SendMessage(hEgrid, %EG_REFRESHALL, 0, 0)

Function = %TRUE

End Function



Also, pressing F2 while focusing a cell, starts editing curent text. just like in Excel. :)

Another trick would be retrienving text before edition starts, then usie the handle of the textbox to replace to the new text.

:)

Elias Montoya

Here is some more code for you, you can play with it to get the hang of it.
it hides the selection as soon as firefly creates the grid, then it makes it visible when edition starts... and hides it again when edition ends.

'------------------------------------------------------------------------------------------------------------------------
Function FORM1_EGRID321_EGN_AFTERPROPERTIES (ControlIndex As Dword, HwndForm As Dword, hEGrid As Long, wParam As Dword, lParam As Long) As Long                                                
' Temporarily hide selection                                                
SendMessage(hEgrid, %EG_SETSELSHOWSTATE, %FALSE, 0)
End Function

'------------------------------------------------------------------------------------------------------------------------
Function FORM1_EGRID321_EGN_CELLLEFTCLICK (ControlIndex As Dword, HwndForm As Dword, hEGrid As Long, wParam As Dword, lParam As Long) As Long

Local EGN As EgridNotify Ptr
EGN = lParam
SendMessage(hEgrid, %EG_MOVECURSOR, @EGN.CELL.X, @EGN.CELL.Y)
SendMessage(hEgrid, %EG_OPENEDITION, @EGN.CELL.X, @EGN.CELL.Y)
' Show selection while edition is going on.
SendMessage(hEgrid, %EG_SETSELSHOWSTATE, %TRUE, 0)
SendMessage(hEgrid, %EG_REFRESHALL, 0, 0)

Function = %TRUE

End Function

'------------------------------------------------------------------------------------------------------------------------
Function FORM1_EGRID321_EGN_EDITIONCLOSED (ControlIndex As Dword, HwndForm As Dword, hEGrid As Long, wParam As Dword, lParam As Long) As Long
' Temporarily hide selection                                                
SendMessage(hEgrid, %EG_SETSELSHOWSTATE, %FALSE, 0)
End Function

Dwight Scoles

Thank you Elias!

I've seen your posts where you state that you can do just about anything with EZGrid.  It is full of surprises!   :shock:

When you mention a handle to a textbox, are you referring to manipulating the contents of a cell? Or are you suggesting overlaying a cell with a separate control that is a textbox, and then moving the data in and out of that text box in a way that the user does not percieve?

QuoteAnother trick would be retrienving text before edition starts, then usie the handle of the textbox to replace to the new text.

Do you have any examples with this type of coding?

Thanks,
Dwight  

:lol: Your newest fan!

Elias Montoya

Egrid32 stores the text in a memory space defined specially for this
purpose.

But when user is editing the text of a cell, Egrid32 uses a normal
textbox. It retrieves cell text from his special location and adds the
text to the textbox that will be used for edition.

Then Egrid 32 sends the notification %EGN_STARTEDIT, wich includes
the handle of this textbox.

During edition, original text is still stored in the grid, so, user can press
ESC and the edition is cancelled.

When edition is about to be closed, Egrid32 sends the notification EGN_FINISHEDIT, Wich also includes the handle of this textbox. Here you can retrieve the text and see if it fits your needs, if it doesnt, you can cancel edition closing. Once edition finishes successfully, Egrid32 retrieves the text from the textbox tht was used, and replaces the text stored internally with this new text.

Now you know more about Egrid32. :)

Dwight Scoles

Thanks Elias.

The SendMessage(hEgrid, %EG_SETSELSHOWSTATE, %FALSE, 0) did the trick for truning off the selection box.  I'll use it as part of the pre-process for each of the grids.

The other recommendation on turning on and off the edit and capturing the values before the user exists is exactly what I need.  It will be a few days before I can get back to working on that part of the code.

Thank you for your support.  It will make this project a reality rather than just a distant possibility.

Dwight