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 »

I nearly mentioned that you'd have a problem here, but you seemed adamant that the cell wouldn't be selected.

If the cell is selected, then the #egrid_cellUpdated message will NOT fire until the focus moves to another cell etc.

After all, the #egrid_cellUpdated message is intended to allow the developer to write changes to cells back to a database etc. Consequently the message is only sent when it is absolutely necessary, i.e. when it is very likely that the changes made to a cell are final. This is usually when the user selects another cell etc.

The only exceptions are CheckBox cells which are not selected. Changes to these have to be notified immediately.

At present it is not possible to be notified when a user clicks a checkmark on a cell which is selected. You have to wait until the user selects another cell.

The only real way around this is for me to introduce another CellCallback message.

Is this very important?
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: Is this very important?
This is required for my program. I will ever give information of count
selected checkboxes in first row.

This information also a wish from other users of my program, i hope you can
help me.

I can't count this every time without event, sometimes i have over 5000 rows
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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Why not prohibit that first column from being selected? The checkmarks can then still be altered.

I must admit that, when I used your program, I did think it a little strange that you could select those cells in the first column.

If you look at demo program 7, you will see how to prevent the selection of such cells but also control cell navigation etc. I think it can work quite well.

However, if you insist ( :wink: ), I will add an extra CellCallback message.
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 »

the source from example 7 works fine, but in my source, i can selected column 0 :cry:

Code: Select all

egrid_CreateGrid(#egrid, 5, 5, 0, 0, 20, #egrid_AlwaysShowSelection, #egrid_CustomHeader | #egrid_ResizeColumnsTrue)
I don't know, what is missing

Code: Select all

    Case #egrid_SelectCell
;       If *cellinfo\column = 0
;         If CountSelected() <> Count
;           Count = CountSelected()
;           SetWindowTitle(0, "Lib2PBImport - " + LibName + "     [" + Str(CountSelected()) + " of " + Str(egrid_NumberOfRows(#egrid)) + " Functions selected]")
;         EndIf
;         result = #False
;       EndIf

      If *cellinfo\column = 0
        Select *cellinfo\param
          Case #egrid_LeftClick    
            egrid_MakeCellVisible(#egrid, 0, *cellinfo\row)
            result = #False
          Case #egrid_ShiftTab
            If *cellinfo\row > 0
              *cellinfo\row - 1
              *cellinfo\column = egrid_NumberOfColumns(#egrid) - 1          
            Else          
              egrid_MakeCellVisible(#egrid, 0, *cellinfo\row)
              result = #False
            EndIf
          Default
            egrid_MakeCellVisible(#egrid, 0, *cellinfo\row)
            *cellinfo\column = #True    
        EndSelect
      EndIf
      result = #True
      RedrawWindow_(GadgetID(#egrid), 0, 0, #RDW_INTERNALPAINT|#RDW_ERASE|#RDW_INVALIDATE)
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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

It doesn't look like you've copied this code from demo 7 correctly.

Third line from the bottom:

Code: Select all

result=#true
is causing every selection to proceed. You need to move this to immediately below the Case #egrid_SelectCell.

Also, change *cellinfo\column = #True to *cellinfo\column = 1 as this is a column number rather than a boolean value.
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 »

okay, but doesn't work :cry:

i think this is the problem:

Code: Select all

    Case #egrid_FormatCell
      If Not *cellinfo\row = -1
        *cellinfo\forecolour = 8421376
      EndIf
      If Not *cellinfo\row % 2
        *cellinfo\backcolour = 14811135
      EndIf
      If *cellinfo\row<> - 1 And *cellinfo\row = egrid_SelectedRow(#egrid)
        *cellinfo\backcolour = $A5F4F9
      EndIf
    Default
      result = #True
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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

That works fine when pasted in demo 7.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

In the #egrid_SelectCell handler, you should remove the RedrawWindow_().
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 »

here the complett cellcallback

Code: Select all

Procedure.l CellCallBack(egrid, uMsg, *cellinfo.egridCellInfo)
  Protected result, i
  Static ENABLED, CDECL, Count = -1
  Protected cbString.s
  For i = 0 To 25
    cbString + Str(i) + #LF$
  Next
  cbString + "26"

  Select uMsg
    Case #egrid_HeaderItemClick
      Select *cellinfo\column
        Case 0
          ENABLED ! 1
          For I = 0 To egrid_NumberOfRows(#egrid)
            If Not ENABLED
              egrid_SetCellText(#egrid, 0, i, "TRUE")
            Else
              egrid_SetCellText(#egrid, 0, i, "FALSE")
            EndIf
          Next
          If CountSelected() <> Count
            Count = CountSelected()
            SetWindowTitle(0, "Lib2PBImport - " + LibName + "     [" + Str(CountSelected()) + " of " + Str(egrid_NumberOfRows(#egrid)) + " Functions selected]")
          EndIf            
        Case 4
          CDECL ! 1
          For I = 0 To egrid_NumberOfRows(#egrid)
            If CDECL
              egrid_SetCellText(#egrid, 4, i, "TRUE")
            Else
              egrid_SetCellText(#egrid, 4, i, "FALSE")
            EndIf
          Next
      EndSelect

    Case #egrid_InsertChar
      Select *cellinfo\column
        Case 0
          result = #True
          If CountSelected() <> Count
            Count = CountSelected()
            SetWindowTitle(0, "Lib2PBImport - " + LibName + "     [" + Str(CountSelected()) + " of " + Str(egrid_NumberOfRows(#egrid)) + " Functions selected]")
          EndIf        
        Case 2
          Select *cellinfo\param
            Case 0 To 48, 58 To 64, 91 To 94, 96, 123 To 255
              result = #False
            Default
              result = #True
          EndSelect
        Case 5
          result = #True
        Case 3
          If *cellinfo\param > 47 And *cellinfo\param < 58
            result = #True
          EndIf
      EndSelect

    Case #egrid_DeleteChar
      result = #True
      If *cellinfo\column = 0
        If CountSelected() <> Count
          Count = CountSelected()
          SetWindowTitle(0, "Lib2PBImport - " + LibName + "     [" + Str(CountSelected()) + " of " + Str(egrid_NumberOfRows(#egrid)) + " Functions selected]")
        EndIf          
      EndIf

    Case #egrid_CellUpdated
      result = #True
      If *cellinfo\column = 0
        egrid_SetCellText(#egrid, 0, *cellinfo\row, *cellinfo\text) 
        If CountSelected() <> Count
          Count = CountSelected()
          SetWindowTitle(0, "Lib2PBImport - " + LibName + "     [" + Str(CountSelected()) + " of " + Str(egrid_NumberOfRows(#egrid)) + " Functions selected]")
        EndIf
      EndIf

    Case #egrid_SelectCell
;       If *cellinfo\column = 0
;         If CountSelected() <> Count
;           Count = CountSelected()
;           SetWindowTitle(0, "Lib2PBImport - " + LibName + "     [" + Str(CountSelected()) + " of " + Str(egrid_NumberOfRows(#egrid)) + " Functions selected]")
;         EndIf
;         result = #False
;       EndIf

      If *cellinfo\column = 0
        Select *cellinfo\param
          Case #egrid_LeftClick    
            egrid_MakeCellVisible(#egrid, 0, *cellinfo\row)
            result = #True
          Case #egrid_ShiftTab
            If *cellinfo\row > 0
              *cellinfo\row - 1
              *cellinfo\column = egrid_NumberOfColumns(#egrid) - 1          
            Else          
              egrid_MakeCellVisible(#egrid, 0, *cellinfo\row)
              result = #False
            EndIf
          Default
            egrid_MakeCellVisible(#egrid, 0, *cellinfo\row)
            *cellinfo\column = 1    
        EndSelect
      EndIf
      result = #True
      RedrawWindow_(GadgetID(#egrid), 0, 0, #RDW_INTERNALPAINT|#RDW_ERASE|#RDW_INVALIDATE)

    Case #egrid_LosingFocus
      result = #True
      RedrawWindow_(GadgetID(#egrid), 0, 0, #RDW_INTERNALPAINT|#RDW_ERASE|#RDW_INVALIDATE)
     
    Case #egrid_NotifyCellType
      Select *cellinfo\column
        Case 3
          *cellinfo\celltype = #egrid_ComboBox
          *cellinfo\text = cbString
        Case 0, 4
          *cellinfo\celltype = #egrid_CheckBox
          *cellinfo\text = "TRUE/FALSE"
        Case 1
          *cellinfo\celltype = #egrid_StaticString
      EndSelect

    Case #egrid_FormatCell
      If Not *cellinfo\row = -1
        *cellinfo\forecolour = 8421376
      EndIf
      If Not *cellinfo\row % 2
        *cellinfo\backcolour = 14811135
      EndIf
      If *cellinfo\row<> - 1 And *cellinfo\row = egrid_SelectedRow(#egrid)
        *cellinfo\backcolour = $A5F4F9
      EndIf
    Default
      result = #True
  EndSelect
  ProcedureReturn result
EndProcedure
column 0 is selectable, i don't know
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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Does this work:

Code: Select all

Case #egrid_SelectCell 
    result=1 
    If *cellinfo\column=0 
      Select *cellinfo\param ;Informs us how the user attempted to select the cell. 
        Case #egrid_LeftClick    
          egrid_MakeCellVisible(#egrid, 0, *cellinfo\row) 
          result=0 ;Refuse the selection. 
        Case #egrid_ShiftTab 
          If *cellinfo\row>0 
            *cellinfo\row-1 
            *cellinfo\column=egrid_NumberOfColumns(#egrid)-1          
          Else          
            egrid_MakeCellVisible(#egrid, 0, *cellinfo\row) 
            result=0 ;Refuse the selection. 
          EndIf 
        Default 
          egrid_MakeCellVisible(#egrid, 0, *cellinfo\row) 
          *cellinfo\column=1    
      EndSelect 
    EndIf 
 RedrawWindow_(GadgetID(#egrid), 0, 0, #RDW_INTERNALPAINT|#RDW_ERASE|#RDW_INVALIDATE) 
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:Does this work:
this works, thanks again
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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

It was simply the fact that you'd placed the 'result = 1' right at the end of the #egrid_SelectCell handler which was cancelling out the custom cell navigation code! :) I simply moved this to the beginning.

:)
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 »

In german, we say: I did not see the wood before nothing but trees
"Ich sah den Wald vor lauter Bäumen nicht!" :D

Thanks for your help and thanks again for egrid4
Last edited by ts-soft on Thu Jan 18, 2007 1:56 am, edited 1 time in total.
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
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. It looks good in your Lib2PBImport application.
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 »

sorry, new problem :wink:
If UserResizeColumn, egrid looses the selection :cry:

Thomas
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
Post Reply