egrid 4 grid gadget - (static PB library version.)

Developed or developing a new product in PureBasic? Tell the world about it.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

ts-soft wrote:sorry, new problem :wink:
If UserResizeColumn, egrid looses the selection :cry:

Thomas
This is by design, mainly because of difficulties with win 98.

See demo program 5 for an example of how to easily reinstate the selection box after a column resize. :)
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

srod wrote:See demo program 5 for an example of how to easily reinstate the selection box after a column resize. :)
thx, this works okay :D
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
zikitrake
Addict
Addict
Posts: 868
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

Hi, in the EGRID DEMO3, how can I maintaining the selection with the GRID in readonly mode?

Code: Select all

;******************************************************************************************
;'egrid4' editable grid control. By Stephen Rodriguez.
;******************************************************************************************

;                                 DEMONSTRATION PROGRAM 3.


;******************************************************************************************
;This demo program sets up a simple egrid with some button type cells.
;It also shows how to dynamically colour cells as the user moves the selection around.
;******************************************************************************************

;XIncludeFile "egrid4.pb"
DisableExplicit

;*****************************************FONT DATA****************************************
Enumeration
  #head1
  #head2
  #main
EndEnumeration
LoadFont(#main, "Arial", 9)
;SetGadgetFont(#PB_Default,FontID(#main))
;******************************************************************************************


Procedure.l MyCellCallBack(egrid, uMsg, *cellinfo.egridCellInfo)
  Protected result
  Select uMsg
    Case #egrid_SelectCell
      ;Here we arrange for the selected row and column to be coloured blue.
      ;This requires a complete redraw of the egrid.
      ;The actual colouring has to be notified in the #egrid_FormatCell message below.
      result=#True
      RedrawWindow_(GadgetID(1), 0, 0, #RDW_INTERNALPAINT|#RDW_ERASE|#RDW_INVALIDATE)

    Case #egrid_LosingFocus
      ;As part of colouring the selected row and column blue, we must arrange to clear these
      ;colours whenever the selection box is removed.
      ;The actual colouring has to be notified in the #egrid_FormatCell message below.
      result=#True
      RedrawWindow_(GadgetID(1), 0, 0, #RDW_INTERNALPAINT|#RDW_ERASE|#RDW_INVALIDATE)

    Case #egrid_NotifyCellType
      If *cellinfo\column=0
        *cellinfo\celltype=#egrid_Button      
      EndIf

    Case #egrid_FormatCell
        If *cellinfo\row<>-1 And *cellinfo\row=egrid_SelectedRow(1); And *cellinfo\column=egrid_SelectedColumn(1)
          *cellinfo\backcolour = $A5F4F9
        ElseIf *cellinfo\row<>-1 And  (*cellinfo\row=egrid_SelectedRow(1) Or *cellinfo\column=egrid_SelectedColumn(1))
          ;*cellinfo\backcolour = #Blue
;Debug Str(*cellinfo\row)+" "+Str(*cellinfo\column)
        EndIf
    Case #egrid_CellButtonClick 
      Debug "Clicked row "+Str(*cellinfo\row)

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


;*************************************WINDOW + GADGET LIST*********************************
If OpenWindow(0,0,0,640,300,"egrid4 demo 3.",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_Maximize|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  ;******************************************************************************************
  
  
  ;********************************************EGRID*****************************************
  ;Create an egrid with resizable columns.
  egrid_CreateGrid(1, WindowWidth(0)/4, WindowHeight(0)/8, WindowWidth(0)/2, WindowHeight(0)/2,26,#egrid_GridLines, #egrid_ResizeColumnsTrue|#egrid_MultiLineText)
  ;******************************************************************************************
  egrid_CreateCellCallback(1, @MyCellCallBack())
  egrid_SetHeaderHeight(1, 26)

  egrid_SetOptions(1, -1, #Black, 2, -1) ; gadgetnum, header border colour, selection border colour, selection border width, gridline colour

  ;********************************************TEXT GADGET***********************************
  
  ;***************************************ADD COLUMNS AND ROWS TO EGRID**********************************
  egrid_AddColumn(1,0,"",60)
  For b=1 To 4 ;50 columns. 
    egrid_AddColumn(1,b,"Col " + Str(b-1),60)
  Next
  For b=0 To 99            ; Add 10 rows.
    egrid_AddRow(1,-1)
    egrid_SetCellText(1, 0,b, "Row "+Str(b))
  Next
  
  ;*****************************************EVENT LOOP***************************************
  Repeat
    EventID = WaitWindowEvent()
    
    Select EventID
      
      Case #PB_Event_Gadget
        Select EventGadget() 
        EndSelect
    EndSelect
  Until EventID = #PB_Event_CloseWindow
  
EndIf
  
End
Thank you for this great lib!
PB 6.21 beta, PureVision User
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Hi, I'm not sure what you mean by read-only mode? Do you mean that you wish to prevent the editing of cells?
I may look like a mule, but I'm not a complete ass.
zikitrake
Addict
Addict
Posts: 868
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

srod wrote:Hi, I'm not sure what you mean by read-only mode? Do you mean that you wish to prevent the editing of cells?
Yes!... sorry, my english is very(very very) bad! :oops:
PB 6.21 beta, PureVision User
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

The quickest way is to switch all cells to type #egrid_StaticString.

Code: Select all

;****************************************************************************************** 
;'egrid4' editable grid control. By Stephen Rodriguez. 
;****************************************************************************************** 

;                                 DEMONSTRATION PROGRAM 3. 


;****************************************************************************************** 
;This demo program sets up a simple egrid with some button type cells. 
;It also shows how to dynamically colour cells as the user moves the selection around. 
;****************************************************************************************** 

;XIncludeFile "egrid4.pb" 
DisableExplicit 

;*****************************************FONT DATA**************************************** 
Enumeration 
  #head1 
  #head2 
  #main 
EndEnumeration 
LoadFont(#main, "Arial", 9) 
;SetGadgetFont(#PB_Default,FontID(#main)) 
;****************************************************************************************** 


Procedure.l MyCellCallBack(egrid, uMsg, *cellinfo.egridCellInfo) 
  Protected result 
  Select uMsg 
    Case #egrid_SelectCell 
      ;Here we arrange for the selected row and column to be coloured blue. 
      ;This requires a complete redraw of the egrid. 
      ;The actual colouring has to be notified in the #egrid_FormatCell message below. 
      result=#True 
      RedrawWindow_(GadgetID(1), 0, 0, #RDW_INTERNALPAINT|#RDW_ERASE|#RDW_INVALIDATE) 

    Case #egrid_LosingFocus 
      ;As part of colouring the selected row and column blue, we must arrange to clear these 
      ;colours whenever the selection box is removed. 
      ;The actual colouring has to be notified in the #egrid_FormatCell message below. 
      result=#True 
      RedrawWindow_(GadgetID(1), 0, 0, #RDW_INTERNALPAINT|#RDW_ERASE|#RDW_INVALIDATE) 

    Case #egrid_NotifyCellType 
      If *cellinfo\column=0 
        *cellinfo\celltype=#egrid_Button      
      Else
        *cellinfo\celltype=#egrid_Staticstring      
      EndIf 

    Case #egrid_FormatCell 
        If *cellinfo\row<>-1 And *cellinfo\row=egrid_SelectedRow(1); And *cellinfo\column=egrid_SelectedColumn(1) 
          *cellinfo\backcolour = $A5F4F9 
        ElseIf *cellinfo\row<>-1 And  (*cellinfo\row=egrid_SelectedRow(1) Or *cellinfo\column=egrid_SelectedColumn(1)) 
          ;*cellinfo\backcolour = #Blue 
;Debug Str(*cellinfo\row)+" "+Str(*cellinfo\column) 
        EndIf 
    Case #egrid_CellButtonClick 
      Debug "Clicked row "+Str(*cellinfo\row) 

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


;*************************************WINDOW + GADGET LIST********************************* 
If OpenWindow(0,0,0,640,300,"egrid4 demo 3.",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_Maximize|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  ;****************************************************************************************** 
  
  
  ;********************************************EGRID***************************************** 
  ;Create an egrid with resizable columns. 
  egrid_CreateGrid(1, WindowWidth(0)/4, WindowHeight(0)/8, WindowWidth(0)/2, WindowHeight(0)/2,26,#egrid_GridLines, #egrid_ResizeColumnsTrue|#egrid_MultiLineText) 
  ;****************************************************************************************** 
  egrid_CreateCellCallback(1, @MyCellCallBack()) 
  egrid_SetHeaderHeight(1, 26) 

  egrid_SetOptions(1, -1, #Black, 2, -1) ; gadgetnum, header border colour, selection border colour, selection border width, gridline colour 

  ;********************************************TEXT GADGET*********************************** 
  
  ;***************************************ADD COLUMNS AND ROWS TO EGRID********************************** 
  egrid_AddColumn(1,0,"",60) 
  For b=1 To 4 ;50 columns. 
    egrid_AddColumn(1,b,"Col " + Str(b-1),60) 
  Next 
  For b=0 To 99            ; Add 10 rows. 
    egrid_AddRow(1,-1) 
    egrid_SetCellText(1, 0,b, "Row "+Str(b)) 
  Next 
  
  ;*****************************************EVENT LOOP*************************************** 
  Repeat 
    EventID = WaitWindowEvent() 
    
    Select EventID 
      
      Case #PB_Event_Gadget 
        Select EventGadget() 
        EndSelect 
    EndSelect 
  Until EventID = #PB_Event_CloseWindow 
  
EndIf 
  
End
I may look like a mule, but I'm not a complete ass.
zikitrake
Addict
Addict
Posts: 868
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

:D yes!... thank you for the fast reply
PB 6.21 beta, PureVision User
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You're welcome.

You can of course switch the cells from #egrid_String to #egrid_StaticString and back again at will in order to switch in and out of 'read only' mode. :)
I may look like a mule, but I'm not a complete ass.
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Post by Thorsten1867 »

I need in the callback the cell text for '#egrid_FormatCell'
to decide, which color I need (Marks: 1-2 green / 5-6 red).
Is this possible?
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Just use egrid_getCellText(#egrid, *cellinfo\column, *cellinfo\row)
I may look like a mule, but I'm not a complete ass.
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Post by Thorsten1867 »

Thanks! That's easy. I'm afraid, I thought in the wrong direction.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

:)
I may look like a mule, but I'm not a complete ass.
zikitrake
Addict
Addict
Posts: 868
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

Any simple sample to use #WM_LBUTTONDBLCLK in normal PB LOOP?

In my code, the event never occurs on my Egrid gadget

Code: Select all

Repeat
      EventID  =WaitWindowEvent()
      MenuID   =EventMenu()
      GadgetID =EventGadget()
      WindowID =EventWindow()
      
      MENU_EVENTOS(EventID, MenuID, GadgetID, WindowID)
      
      Select EventID
        Case #WM_LBUTTONDBLCLK
          SetWindowTitle(#Window_Principal,"DBLCLICK ON GADGET:" +Str(GadgetID) + " - " + Str(Random(10)))
          If GadgetID = #My_Egrid
            MessageRequester("hey!", "double click on Egrid")
          EndIf
      EndSelect
;.....
;.....
    ForEver
PB 6.21 beta, PureVision User
zikitrake
Addict
Addict
Posts: 868
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

[AutoAnswer]

replace

Code: Select all

If GadgetID = #My_Egrid
by

Code: Select all

If  GetActiveGadget() = #My_Egrid
[/AutoAnswer]
PB 6.21 beta, PureVision User
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

#WM_LBUTTONDBLCLK works fine here. There's a slight problem in that the second click is sometimes swallowed by the various controls used to edit certain cells etc.
I may look like a mule, but I'm not a complete ass.
Post Reply