Page 17 of 23

Posted: Wed Apr 08, 2009 6:15 pm
by JCV
thanks! 8)

Column resize

Posted: Thu Jun 04, 2009 6:10 pm
by univeda
I just purchased Es_Grid and run into my first problem:

I have a egrid placed inside a splitter. When i resize my window, i resize the splitter and the embedded egrid seems to resize as well.

All i want to do is to resize the width of the egrid-columns so that they fill my egrid complete.

I did now find anything about resizing columns in the help-file.

Any ideas?

Edit:

Found this hint inside the egrid-help:

Code: Select all

SendMessage_(GadgetID(#egrid), #LVM_SETCOLUMNWIDTH, lastcolindex+1, #LVSCW_AUTOSIZE_USEHEADER)
I use this now inside a loop across all colums:

Code: Select all

for i = 1 to numCols
SendMessage_(GadgetID(#egrid), #LVM_SETCOLUMNWIDTH, i, #LVSCW_AUTOSIZE_USEHEADER)
next
Works. Is there another egrid build-in function to resize the columns?

Posted: Thu Jun 04, 2009 10:25 pm
by srod
An EsGRID is a sub-classed Purebasic ListIcon gadget and so you can use SetGadgetItemAttribute() to alter a column width etc. This is why I did not add such a command to the EsGRID library.

Just remember to add 1 to the coumn index before using SetGadgetItemAttribute() etc.

Posted: Fri Jun 05, 2009 8:37 am
by univeda
srod wrote:Just remember to add 1 to the coumn index before using SetGadgetItemAttribute() etc.
Thank you, Stephen, SetGatdgetItemAttribute works fine with your egrid. But why should i add 1 to the column index?

Posted: Fri Jun 05, 2009 11:41 am
by srod
univeda wrote:Thank you, Stephen, SetGatdgetItemAttribute works fine with your egrid. But why should i add 1 to the column index?
That is explained somewhere in the manual! :)

An EsGRID is a heavily modifed ListIcon gadget with column zero blanked out (for various reasons). Consequently, what EsGRID regards as column 0, for example, Purebasic and Windows regard as column 1 and so on.

Posted: Fri Jun 05, 2009 1:21 pm
by univeda
ok, understood.

Is there somewhere in the manual a hint how to easily realize something like alternating rowColors?

Posted: Fri Jun 05, 2009 1:31 pm
by srod
I think the various demos would show you the way! :wink: Demo 7 in particular colors alternate rows and arranges for the selected row to be colored differently etc.

A simple CellCallback function is all you need.

If you wish a simple example then just let me know and I'll hack one up for you in 20 seconds! :wink:

Posted: Fri Jun 05, 2009 11:25 pm
by univeda
Thank you again.

I managed it by using this:

Code: Select all

Procedure.i egridCellCallBack(egrid, uMsg, *cellinfo.egridCellInfo)
  Protected result
  Select uMsg
    Case #egrid_HeaderItemClick
     ;Debug "From CellCallback function: column " + Str(*cellinfo\column) + " clicked."
     Case #egrid_FormatCell
        If *cellinfo\row = -1 ;Custom header.
          *cellinfo\textjustification = #egrid_centerText
        Else
          If *cellinfo\row % 2 ;Alternating rowColor
            *cellinfo\backcolour = RGB($E3, $F1, $FF)
            *cellinfo\forecolour = #Black
          Else
            *cellinfo\backcolour = #White
          EndIf
        EndIf
    Default 
      result = #True
  EndSelect
  ProcedureReturn result
EndProcedure
Works fine. Your esgrid is really very flexible. Keep up the good work!

Posted: Fri Jun 05, 2009 11:27 pm
by srod
univeda wrote:Works fine. Your esgrid is really very flexible. Keep up the good work!
I always do! :wink:

I'm glad you sorted things out.

Posted: Mon Jun 08, 2009 4:35 pm
by univeda
Hi Stephen,

getting more and more into it but... can you please enlight me once again?

I've worked with your examples 3 and 7 but couldn't realize what i call a FullRowSelect.

Can you please provide (and explain) a sample how to use the CellCallBack so that a row is completly selected after a cell in this row is selected?

Thanks again.

Michael

Posted: Mon Jun 08, 2009 4:58 pm
by srod
Well, I am not sure there is much I can say beyond what is in demo 3.

First thing to say is that you do not select rows; only cells. This is the same for any grid. What you presumably mean is that you want to highlight the entire row whenever the user selects a cell etc.

In any example, the #egrid_FormatCell handler is responsible for coloring cells. So, for example, in the following #egrid_FormatCell handler, we arrange for every cell within the selected row to have a background color of blue.

Code: Select all

Case #egrid_FormatCell 
  If *cellinfo\row<>-1 And *cellinfo\row=egrid_SelectedRow(1)
      *cellinfo\backcolour = #Blue
  EndIf 
Now this is fine, except it will not work properly as yet. If you were to add this to an example, you will find that only the selected cell was getting a background of blue and then some cells would remain with a blue background after you move the focus!

This is because the #egrid_FormatCell message is sent for individual cells only. We need a way of getting this message to fire for all cells within the selected row whenever the user selects a new cell etc.

For this, simply add the following command at the end of your #egrid_SelectCell handler to force a repaint :

Code: Select all

InvalidateRect_(GadgetID(egrid),0,0)
You will need a similar line at the end of your #egrid_LosingFocus handler.

Here's a very simple example taking the above points into account :

Code: Select all

IncludePath "..\Source\"
  XIncludeFile "EsGRID.pbi"
IncludePath ""

Procedure.l MyCellCallBack(egrid, uMsg, *cellinfo.egridCellInfo) 
  Protected result 
  Select uMsg 
    Case #egrid_SelectCell 
      result=#True 
      InvalidateRect_(GadgetID(egrid),0,0)
    Case #egrid_LosingFocus 
      result=#True 
      InvalidateRect_(GadgetID(egrid),0,0)

    Case #egrid_FormatCell 
      If *cellinfo\row<>-1 And *cellinfo\row=egrid_SelectedRow(egrid) 
        *cellinfo\backcolour = $A5F4F9 
      EndIf 

    Default 
      result = #True                       ;This accounts for all messages we have decided not to process. 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

If OpenWindow(0,0,0,640,300,"EsGRID demo.",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_Maximize|#PB_Window_ScreenCentered)
  
  egrid_CreateGrid(1, WindowWidth(0)/4, WindowHeight(0)/8, WindowWidth(0)/2, WindowHeight(0)/2,26,#egrid_GridLines|#egrid_AlwaysShowSelection, #egrid_ResizeColumnsTrue|#egrid_MultiLineText) 

  egrid_CreateCellCallback(1, @MyCellCallBack()) 
  egrid_SetHeaderHeight(1, 42) 

  egrid_setOption(1, #egrid_SelectionBorderColour, #Black)
  egrid_setOption(1, #egrid_SelectionBorderWidth, 2)

  For b=0 To 4 ;5 columns. 
    egrid_AddColumn(1,b,"Col " + Str(b),60) 
  Next 
  egrid_AddRows(1,-1, 100) 
  
  Repeat 
    EventID = WaitWindowEvent() 
  Until EventID = #PB_Event_CloseWindow 
  
EndIf
You may want to remove the focus rectangle from the selected cell by switching :

Code: Select all

egrid_setOption(1, #egrid_SelectionBorderWidth, 2)
for

Code: Select all

egrid_setOption(1, #egrid_SelectionBorderWidth, 0)

Posted: Mon Jun 08, 2009 6:59 pm
by univeda
Perfect, thanks for your explanation. This made it much more understandable.

Michael

Posted: Sat Jun 13, 2009 12:13 pm
by univeda
I use a CellCallBack to display the CellText as a CellTooltip:

Code: Select all

Case #egrid_GetCellTooltip
        *cellinfo\text = eGrid_GetCellText(egrid, *cellinfo\column, *cellinfo\row)
      result = #True
But with some special characters (like this one -> &) there are problems, the &-sign is shown as this: _

Do i have to set a chracter-set or somethins like that?

Michael

Posted: Sat Jun 13, 2009 1:01 pm
by srod
I have altered the EsGRID source not to do that anymore.

Rather than me uploading a new version just for this change; let me direct you to make the alteration yourself.

Load up the main "EsGRID.pbi" source and find the line :

Code: Select all

*pointer\ttip = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP, 0, 0, 0, 0, 0, 0, 0, 0) 
(Just search for Tooltips_Class32).


Change the line to :

Code: Select all

*pointer\ttip = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP|#TTS_NOPREFIX, 0, 0, 0, 0, 0, 0, 0, 0) 

**EDIT : univeda, could I please ask that you join the forums over at the nxSoftware site where there is a whole section given over to EsGRID.

Posted: Sat Jun 13, 2009 1:30 pm
by univeda
Thanks, this works.

I've joined your forum now.