Posted: Wed Nov 08, 2006 11:19 am
Tailbite seems to rename it for some reason and I keep forgetting to change the name!
I'll do something about it!
I'll do something about it!

http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
;******************************************************************************************
;'egrid4' editable grid control. By Stephen Rodriguez.
;******************************************************************************************
; DEMONSTRATION PROGRAM 7.
;******************************************************************************************
;This demo program sets up an egrid which shows how to use a Cellcallback funtion to validate
;cell selection etc.
;******************************************************************************************
;XIncludeFile "egrid4.pb"
DisableExplicit
Global gLastOption
LoadFont(1, "Arial", 10)
;************************************CELLCALLBACK FUNCTION*********************************
;NOTE, THIS IS NOT A PROPER WINDOWS CALLBACK!
Procedure.l MyCellCallBack(egrid, uMsg, *cellinfo.egridCellInfo)
Protected result
Select uMsg
Case #egrid_CellUpdated
If *cellinfo\column = 0
If gLastOption<>-1 And gLastOption <> *cellinfo\row
egrid_SetCellText ( 1, 0, gLastOption, "FALSE" )
EndIf
gLastOption=*cellinfo\row
EndIf
result=1
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(1, 0, *cellinfo\row)
result=0 ;Refuse the selection.
Case #egrid_ShiftTab
If *cellinfo\row>0
*cellinfo\row-1
*cellinfo\column=egrid_NumberOfColumns(1)-1
Else
egrid_MakeCellVisible(1, 0, *cellinfo\row)
result=0 ;Refuse the selection.
EndIf
Default
egrid_MakeCellVisible(1, 0, *cellinfo\row)
*cellinfo\column=1
EndSelect
EndIf
Case #egrid_NotifyCellType
Select *cellinfo\column
Case 0
*cellinfo\celltype=#egrid_CheckBox
*cellinfo\text="TRUE/FALSE"
EndSelect
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 7.",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_Maximize|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
;******************************************************************************************
text$="The following grid only allows one checkmark to be set at any one time."
text$+Chr(13)+Chr(10)+Chr(13)+Chr(10)+"It also does not allow any cell in column 0 to be selected."
text$+" When doing this you need to take care with validating cell navigation to ensure that column 0 remains visible."
text$+Chr(13)+Chr(10)+Chr(13)+Chr(10)+"Both of these features are controlled within a CellCallback function."
TextGadget(0, WindowWidth(0)/12,20, 800, 120, text$)
SetGadgetFont(0, FontID(1))
;********************************************EGRID*****************************************
;Create an egrid with resizable columns.
egrid_CreateGrid(1, WindowWidth(0)/2-175, 150, 350, 300,24,#egrid_GridLines|#egrid_AlwaysShowSelection, #egrid_ResizeColumnsTrue|#egrid_MultiLineText)
text$="NOTE that this would need re-coding if we allowed the user to reorder the columns by click and drag etc."
TextGadget(2, WindowWidth(0)/12,500, 800, 120, text$)
SetGadgetFont(2, FontID(1))
;**********************************SET CELLCALLBACK FUNCTION*******************************
;Set the callback early to avoid massive flickering when populating the egrid with initial data.
egrid_CreateCellCallback(1, @MyCellCallBack())
;******************************************************************************************
;***************************************ADD DATA TO EGRID**********************************
egrid_AddColumn(1,0,"",30)
egrid_AddColumn(1,1,"First name",120)
egrid_AddColumn(1,2,"Second name",120)
egrid_AddColumn(1,3,"Gender",60)
egrid_AddColumn(1,4,"VR",30)
For b=0 To 80 ; Add 100 rows.
egrid_AddRow(1,-1)
egrid_SetCellText(1,0,b,"FALSE")
egrid_SetCellText(1,1,b,"Bob")
egrid_SetCellText(1,2,b,"Smith")
Next
egrid_SetHeaderHeight(1,40)
egrid_SetOptions(1, -1, -1, 2,-1) ; gadgetnum, header border colour, selection border colour, selection border width, gridline colour
SetActiveGadget(1)
;******************************************************************************************
;*****************************************EVENT LOOP***************************************
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
Until EventID = #PB_Event_CloseWindow
EndIf
End
I must differentiate between selecting and doubleclick.srod wrote:However, I can add this if you wish, even though it would be useless for detecting a cell select because this is notified as soon as a #WM_LBUTTONDOWN message is generated.
I don't think you'll be able to do this, unless you forbid certain cells from being selected.Thorsten1867 wrote:I must differentiate between selecting and doubleclick.
I receive a #WM_LBUTTONDBLCLK event okay in a PB event loop!!!I get no Event ( 'EventGadget()' ) if click on an cell/row, like 'ListIconGadget()'. Have you an idea, how I can an doubleclick event (for protected cells)?
Not broken as such!zikitrake wrote:Hi Srod, the download link from http://www.purecoder.net/download.htm
is broken (http://www.purecoder.net/egrid4setup.exe)