Select cell in a ListIconGadget

Just starting out? Need help? Post your questions and find answers here.
drahneir
Enthusiast
Enthusiast
Posts: 105
Joined: Tue Jul 18, 2006 4:18 pm
Location: JO42RM

Select cell in a ListIconGadget

Post by drahneir »

Hello,
I have filled a ListIconGadget with data from a database. Now I want to select a random cell by mouseclick. By 'GetGadgetItemText()' I want to get the content of that cell. But where can I get from the record and column parameters for that command?
Background is, that I want to write the content of the selected cell in a StringGadget, edit it there and write it back to the database.
Any help is appreciated.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Why not use a grid gadget?

There are a few scattered around, for which my offering egrid 3 (based upon a list icon) is to be found in the announcements section.

If you do try egrid 3, please bear in mind that a massively upgraded and refined version is imminent! :)

If this is not appropriate, then you need to consider the #LVM_SUBITEMHITTEST message to get the information you require.

Regards.
I may look like a mule, but I'm not a complete ass.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

If you don't mind using a userlib, you can try PureLVSORT ( http://www.purebasic.fr/english/viewtop ... 24&start=0 ) ; it has these two functions : PureLVSORT_GetClickedCellColumn() and PureLVSORT_GetClickedCellRow().

Example :

Code: Select all

OpenWindow(0, 100, 300, 420, 170, "PureLVSORT test : get clicked cells coordinates", #PB_Window_SystemMenu) 
If CreateGadgetList(WindowID(0)) 
  ListIconGadget(1, 1, 1, 250, 160, "0", 50, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
  AddGadgetColumn(1, 1, "1", 50)
  AddGadgetColumn(1, 2, "2", 50)
  AddGadgetColumn(1, 3, "3", 50)
  AddGadgetColumn(1, 4, "4", 50)
  AddGadgetColumn(1, 5, "5", 50)
  AddGadgetItem(1, -1, " ")
  AddGadgetItem(1, -1, " ")
  AddGadgetItem(1, -1, " ")
  AddGadgetItem(1, -1, " ")
  AddGadgetItem(1, -1, " ")
  AddGadgetItem(1, -1, " ")
  AddGadgetItem(1, -1, " ")
  AddGadgetItem(1, -1, " ")
  AddGadgetItem(1, -1, " ")
  ListIconGadget(2, 260, 1, 150, 160, "0", 50, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
  AddGadgetColumn(2, 1, "1", 50)
  AddGadgetColumn(2, 2, "2", 50)
  AddGadgetItem(2, -1, " ")
  AddGadgetItem(2, -1, " ")
  AddGadgetItem(2, -1, " ")
  AddGadgetItem(2, -1, " ")
  AddGadgetItem(2, -1, " ")
  AddGadgetItem(2, -1, " ")
  AddGadgetItem(2, -1, " ")
  AddGadgetItem(2, -1, " ")
  AddGadgetItem(2, -1, " ")
  AddGadgetItem(2, -1, " ")
  AddGadgetItem(2, -1, " ")
EndIf
PureLVSORT_SelectGadgetToSort(1, #PureLVSORT_ShowClickedHeader_No) ; just to register the gadget's parent window
Repeat 
  EventID.l = WaitWindowEvent()
  GadgetID.l = EventGadget()
  EventType.l = EventType()
  If EventID = #PB_Event_Gadget
    If GadgetID = 1
      Debug "* ListIconGadget 1 Event"
      If EventType = #PB_EventType_LeftClick
        Debug " Left Click at ROW:" + Str(PureLVSORT_GetClickedCellRow()) + " COL:" + Str(PureLVSORT_GetClickedCellColumn())
      ElseIf EventType = #PB_EventType_LeftDoubleClick
        Debug " Left DBL Click at ROW:" + Str(PureLVSORT_GetClickedCellRow()) + " COL:" + Str(PureLVSORT_GetClickedCellColumn())
      ElseIf EventType = #PB_EventType_RightClick
        Debug " Right Click at ROW:" + Str(PureLVSORT_GetClickedCellRow()) + " COL:" + Str(PureLVSORT_GetClickedCellColumn())
      ElseIf EventType = #PB_EventType_RightDoubleClick
        Debug " Right DBL Click at ROW:" + Str(PureLVSORT_GetClickedCellRow()) + " COL:" + Str(PureLVSORT_GetClickedCellColumn())
      EndIf
    EndIf
    If GadgetID = 2
      Debug "* ListIconGadget 2 Event"
      If EventType = #PB_EventType_LeftClick
        Debug "Left Click at ROW:" + Str(PureLVSORT_GetClickedCellRow()) + " COL:" + Str(PureLVSORT_GetClickedCellColumn())
      ElseIf EventType = #PB_EventType_LeftDoubleClick
        Debug " Left DBL Click at ROW:" + Str(PureLVSORT_GetClickedCellRow()) + " COL:" + Str(PureLVSORT_GetClickedCellColumn())
      ElseIf EventType = #PB_EventType_RightClick
        Debug " Right Click at ROW:" + Str(PureLVSORT_GetClickedCellRow()) + " COL:" + Str(PureLVSORT_GetClickedCellColumn())
      ElseIf EventType = #PB_EventType_RightDoubleClick
        Debug " Right DBL Click at ROW:" + Str(PureLVSORT_GetClickedCellRow()) + " COL:" + Str(PureLVSORT_GetClickedCellColumn())
      EndIf
    EndIf
  ElseIf EventID = #PB_Event_CloseWindow 
    Break
  EndIf
ForEver
;
End
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
drahneir
Enthusiast
Enthusiast
Posts: 105
Joined: Tue Jul 18, 2006 4:18 pm
Location: JO42RM

Post by drahneir »

Thanks, srod. Well, I had already downloaded eGrid, but not yet installed, because I want to try it the hard way first :lol: .
But what I use is EasyVent, only one event I exploit, but it is very useful for me. Thanks for that.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Ah, the hard way. A man after my own heart! But I'm sure once you've played around some you'll choose srod's egrid. It's really quite good. For the hard way, here's a bit of fun to point you in the general direction:

Code: Select all

#LVM_SUBITEMHITTEST = #LVM_FIRST + 57
Global oldlist,lv

Procedure SubClass_LV(hwnd, msg, wparam, lparam)
  result = CallWindowProc_(oldlist, hwnd, msg, wparam, lparam)
  If msg = #WM_LBUTTONDOWN
    HitInfo.LVHITTESTINFO
    Hitinfo\pt\x = WindowMouseX(0)
    HitInfo\pt\y = WindowMouseY(0)
    SendMessage_(lv,#LVM_SUBITEMHITTEST,0,@HitInfo)
    SetGadgetItemColor(0,hitinfo\iitem,#PB_Gadget_BackColor,RGB(181, 225, 241),hitinfo\iSubItem)
    Debug GetGadgetItemText(0,hitinfo\iitem,hitinfo\iSubItem)
  EndIf
  ProcedureReturn result
EndProcedure

OpenWindow(0,0,0,640,480,"ListIcon Gadget Mischief: Get Selected Item",$CF0001)
CreateGadgetList(WindowID(0))
lv = ListIconGadget(0,0,0,640,480,"",0,#PB_ListIcon_GridLines)
AddGadgetColumn(0,1,"Column 1",210)
AddGadgetColumn(0,2,"Column 2",210)
AddGadgetColumn(0,3,"Column 3",215)
For i = 1 To 32
  linestr.s = LSet(Str(i),3," ")
  AddGadgetItem(0, -1, Chr(10)+"Text on Line "+linestr+" in Column 1"+Chr(10)+"Text on Line "+linestr+" in Column 2"+Chr(10)+"Text on Line "+linestr+" in Column 3")
Next
oldlist=SetWindowLong_(lv, #GWL_WNDPROC, @SubClass_LV())

Repeat:Until WaitWindowEvent()=#WM_CLOSE
It's pretty easy from here to open a string gadget, take the new value, and replace the ListIcon gadgetitem text with it if you want to do that. Just use SetGadgetItemText on the same parameters. And you'll want to uncolor the box when it's not the active one anymore. I was too lazy to do that.
BERESHEIT
drahneir
Enthusiast
Enthusiast
Posts: 105
Joined: Tue Jul 18, 2006 4:18 pm
Location: JO42RM

Post by drahneir »

Thanks, netmaestro, that would be exactly what I was looking for, when... yes when it would be more accurate. I explain what I mean: there is never highlighted the cell I am clicking on, but one or two cells below, depending on where I click within the cell. So I have substracted 1 from hitinfo\iitem, and when I click in the upper half of a cell, this cell is highlighted and the text is displayed. But when I come near to lower limit, the cell below is it. Very strange behaviour :roll: .
But principally it is the solution.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

A bit more:

Code: Select all

#LVM_SUBITEMHITTEST = #LVM_FIRST + 57 
Global oldlist,lv 

Procedure.s GetNewText(item,subitem) 
  Select subitem 
    Case 1 
      x=WindowX(0)+GadgetX(0)+5 
    Case 2 
      x=WindowX(0)+GadgetX(0)+215 
    Case 3 
      x=WindowX(0)+GadgetX(0)+425 
  EndSelect 
  OpenWindow(1, x,DesktopMouseY()+10,260,20,"",#PB_Window_BorderLess) 
  GetWindowRect_(WindowID(1), editrect.rect) 
  ClipCursor_(editrect) 
  CreateGadgetList(WindowID(1)) 
  StringGadget(1,0,0,190,20,"") 
  ButtonGadget(2,190,0,30,20,"OK") 
  ButtonGadget(3,220,0,40,20,"Cancel") 
  SetActiveGadget(1) 
  AddKeyboardShortcut(1,#PB_Shortcut_Return,1) 
  SetGadgetItemColor(0,item,#PB_Gadget_BackColor,RGB(200,200,200),subitem) 
  quit=0 
  Repeat 
    ev=WaitWindowEvent() 
      If EventWindow()=1 
      Select ev 
        Case #PB_Event_Menu 
          If EventMenu()=1 
            SetGadgetItemText(0,item,GetGadgetText(1),SubItem) 
            CloseWindow(1) 
            quit = 1 
          EndIf 
        Case #PB_Event_Gadget 
          If EventGadget()=2 
            SetGadgetItemText(0,item,GetGadgetText(1),SubItem) 
            CloseWindow(1) 
            quit = 1      
          ElseIf EventGadget() = 3 
            CloseWindow(1) 
            quit = 1    
          EndIf 
      EndSelect 
   EndIf    
  Until quit 
  SetGadgetItemColor(0,item,#PB_Gadget_BackColor,#White,subitem) 
  ClipCursor_(0) 
EndProcedure 

Procedure SubClass_LV(hwnd, msg, wparam, lparam) 
  result = CallWindowProc_(oldlist, hwnd, msg, wparam, lparam) 
  If msg = #WM_RBUTTONDOWN 
    HitInfo.LVHITTESTINFO 
    Hitinfo\pt\x = WindowMouseX(0) 
    HitInfo\pt\y = WindowMouseY(0) 
    SendMessage_(lv,#LVM_SUBITEMHITTEST,0,@HitInfo) 
    GetNewText(hitinfo\iitem,hitinfo\iSubItem) 
  EndIf 
  ProcedureReturn result 
EndProcedure 

OpenWindow(0,0,0,640,480,"ListIcon Gadget Mischief: Edit Selected Item",$CF0001) 
CreateGadgetList(WindowID(0)) 
lv = ListIconGadget(0,0,0,640,480,"",0,#PB_ListIcon_GridLines) 
AddGadgetColumn(0,1,"Column 1",210) 
AddGadgetColumn(0,2,"Column 2",210) 
AddGadgetColumn(0,3,"Column 3",215) 
For i = 1 To 32 
  linestr.s = LSet(Str(i),3," ") 
  AddGadgetItem(0, -1, Chr(10)+"Text on Line "+linestr+" in Column 1"+Chr(10)+"Text on Line "+linestr+" in Column 2"+Chr(10)+"Text on Line "+linestr+" in Column 3") 
Next 
oldlist=SetWindowLong_(lv, #GWL_WNDPROC, @SubClass_LV()) 

Repeat 
  ev = WaitWindowEvent() 

Until ev=#WM_CLOSE 
For what you're doing, you may want to leave the edited cells colored until they get written to the database, to let the user know that they haven't been committed yet. Just as a possible idea.

Actually, I might find this useful myself someday. I'm going to stick it in my sourcecode folder. Thanks for tempting me to write it!
BERESHEIT
drahneir
Enthusiast
Enthusiast
Posts: 105
Joined: Tue Jul 18, 2006 4:18 pm
Location: JO42RM

Post by drahneir »

I have found something, which fulfills my needs perfectly. I have reduced it to what I need and this is the result:

Code: Select all

Procedure Callback(Window.l, Message.l, wParam.l, lParam.l) 
  lRes = #PB_ProcessPureBasicEvents 
  If Message = #WM_NOTIFY        ; these events are send as notification messages 
    Define *pnmh.NMHDR = lParam  ; lParam points to a structure with more info 
    If *pnmh\hwndFrom = GadgetID(#ListIcon_Log) ; see if it is the right gadget 
      If *pnmh\code = #NM_CLICK  ; user clicked in the ListView 
          Define *lpnmitem.NMITEMACTIVATE = lParam 
          lRow = *lpnmitem\iItem 
          lCol = *lpnmitem\iSubItem 
      EndIf
    EndIf 
  EndIf
  ProcedureReturn lRes
EndProcedure 

SetWindowCallback(@Callback()) 
Thanks for all replies.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Hello

I have modified the great code of NETMAESTRO, because i want to put the ListIconGadget in the middle of the form.
But if i do that, the code don't works :cry:

The variable "hitinfo\iitem" in line 60 is already at -1 :shock:
Somebody know why ?????

Code: Select all

#LVM_SUBITEMHITTEST = #LVM_FIRST + 57
Global oldlist,lv 

Procedure.s GetNewText(item,subitem)

  Select subitem 
    Case 1 
      x=WindowX(0)+GadgetX(0)+5 
    Case 2 
      x=WindowX(0)+GadgetX(0)+215 
    Case 3 
      x=WindowX(0)+GadgetX(0)+425 
  EndSelect 
  OpenWindow(1, x,DesktopMouseY()+10,260,20,"",#PB_Window_BorderLess) 
  GetWindowRect_(WindowID(1), editrect.rect) 
  ClipCursor_(editrect) 
  CreateGadgetList(WindowID(1)) 
  StringGadget(1,0,0,190,20,"") 
  ButtonGadget(2,190,0,30,20,"OK") 
  ButtonGadget(3,220,0,40,20,"Cancel") 
  SetActiveGadget(1) 
  AddKeyboardShortcut(1,#PB_Shortcut_Return,1) 
  SetGadgetItemColor(0,item,#PB_Gadget_BackColor,RGB(200,200,200),subitem) 
  quit=0 
  Repeat 
    ev=WaitWindowEvent() 
      If EventWindow()=1 
      Select ev 
        Case #PB_Event_Menu 
          If EventMenu()=1 
            SetGadgetItemText(0,item,GetGadgetText(1),SubItem) 
            CloseWindow(1) 
            quit = 1 
          EndIf 
        Case #PB_Event_Gadget 
          If EventGadget()=2 
            SetGadgetItemText(0,item,GetGadgetText(1),SubItem) 
            CloseWindow(1) 
            quit = 1      
          ElseIf EventGadget() = 3 
            CloseWindow(1) 
            quit = 1    
          EndIf 
      EndSelect 
   EndIf    
  Until quit 
  SetGadgetItemColor(0,item,#PB_Gadget_BackColor,#White,subitem) 
  ClipCursor_(0) 
EndProcedure 

Procedure SubClass_LV(hwnd, msg, wparam, lparam) 
  result = CallWindowProc_(oldlist, hwnd, msg, wparam, lparam) 
  If msg = #WM_RBUTTONDOWN 
    HitInfo.LVHITTESTINFO 
    Hitinfo\pt\x = WindowMouseX(0) 
    HitInfo\pt\y = WindowMouseY(0) 
    SendMessage_(lv,#LVM_SUBITEMHITTEST,0,@HitInfo) 
    GetNewText(hitinfo\iitem,hitinfo\iSubItem) 
    Debug hitinfo\iitem
    Debug hitinfo\iSubItem
  EndIf 
  ProcedureReturn result 
EndProcedure 

OpenWindow(0,0,0,640,480,"ListIcon Gadget Mischief: Edit Selected Item",$CF0001) 
CreateGadgetList(WindowID(0)) 
lv = ListIconGadget(0,0,200,640,180,"",0,#PB_ListIcon_GridLines) 
AddGadgetColumn(0,1,"Column 1",210) 
AddGadgetColumn(0,2,"Column 2",210) 
AddGadgetColumn(0,3,"Column 3",215) 
For i = 1 To 12 
  linestr.s = LSet(Str(i),3," ") 
  AddGadgetItem(0, -1, Chr(10)+"Text on Line "+linestr+" in Column 1"+Chr(10)+"Text on Line "+linestr+" in Column 2"+Chr(10)+"Text on Line "+linestr+" in Column 3") 
Next 
oldlist=SetWindowLong_(lv, #GWL_WNDPROC, @SubClass_LV()) 

Repeat 
  ev = WaitWindowEvent() 

Until ev=#WM_CLOSE 
Thanks for your help
Good day
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Hello

I have modified the great code of NETMAESTRO, because i want to put the ListIconGadget in the middle of the form.
But if i do that, the code don't works :cry:

The variable "hitinfo\iitem" in line 60 is already at -1 :shock:
Somebody know why ?????

Code: Select all

#LVM_SUBITEMHITTEST = #LVM_FIRST + 57
Global oldlist,lv 

Procedure.s GetNewText(item,subitem)

  Select subitem 
    Case 1 
      x=WindowX(0)+GadgetX(0)+5 
    Case 2 
      x=WindowX(0)+GadgetX(0)+215 
    Case 3 
      x=WindowX(0)+GadgetX(0)+425 
  EndSelect 
  OpenWindow(1, x,DesktopMouseY()+10,260,20,"",#PB_Window_BorderLess) 
  GetWindowRect_(WindowID(1), editrect.rect) 
  ClipCursor_(editrect) 
  CreateGadgetList(WindowID(1)) 
  StringGadget(1,0,0,190,20,"") 
  ButtonGadget(2,190,0,30,20,"OK") 
  ButtonGadget(3,220,0,40,20,"Cancel") 
  SetActiveGadget(1) 
  AddKeyboardShortcut(1,#PB_Shortcut_Return,1) 
  SetGadgetItemColor(0,item,#PB_Gadget_BackColor,RGB(200,200,200),subitem) 
  quit=0 
  Repeat 
    ev=WaitWindowEvent() 
      If EventWindow()=1 
      Select ev 
        Case #PB_Event_Menu 
          If EventMenu()=1 
            SetGadgetItemText(0,item,GetGadgetText(1),SubItem) 
            CloseWindow(1) 
            quit = 1 
          EndIf 
        Case #PB_Event_Gadget 
          If EventGadget()=2 
            SetGadgetItemText(0,item,GetGadgetText(1),SubItem) 
            CloseWindow(1) 
            quit = 1      
          ElseIf EventGadget() = 3 
            CloseWindow(1) 
            quit = 1    
          EndIf 
      EndSelect 
   EndIf    
  Until quit 
  SetGadgetItemColor(0,item,#PB_Gadget_BackColor,#White,subitem) 
  ClipCursor_(0) 
EndProcedure 

Procedure SubClass_LV(hwnd, msg, wparam, lparam) 
  result = CallWindowProc_(oldlist, hwnd, msg, wparam, lparam) 
  If msg = #WM_RBUTTONDOWN 
    HitInfo.LVHITTESTINFO 
    Hitinfo\pt\x = WindowMouseX(0) 
    HitInfo\pt\y = WindowMouseY(0) 
    SendMessage_(lv,#LVM_SUBITEMHITTEST,0,@HitInfo) 
    GetNewText(hitinfo\iitem,hitinfo\iSubItem) 
    Debug hitinfo\iitem
    Debug hitinfo\iSubItem
  EndIf 
  ProcedureReturn result 
EndProcedure 

OpenWindow(0,0,0,640,480,"ListIcon Gadget Mischief: Edit Selected Item",$CF0001) ; Line modified (Height of form)
CreateGadgetList(WindowID(0)) 
lv = ListIconGadget(0,0,200,640,180,"",0,#PB_ListIcon_GridLines)  ; Line modified (Y Pos)
AddGadgetColumn(0,1,"Column 1",210) 
AddGadgetColumn(0,2,"Column 2",210) 
AddGadgetColumn(0,3,"Column 3",215) 
For i = 1 To 12  ; Line modified (Number of loop)
  linestr.s = LSet(Str(i),3," ") 
  AddGadgetItem(0, -1, Chr(10)+"Text on Line "+linestr+" in Column 1"+Chr(10)+"Text on Line "+linestr+" in Column 2"+Chr(10)+"Text on Line "+linestr+" in Column 3") 
Next 
oldlist=SetWindowLong_(lv, #GWL_WNDPROC, @SubClass_LV()) 

Repeat 
  ev = WaitWindowEvent() 

Until ev=#WM_CLOSE 
Thanks for your help
Good day
ImageThe happiness is a road...
Not a destination
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Switch the SubClass_LV() function for the following :

Code: Select all

Procedure SubClass_LV(hwnd, msg, wparam, lparam) 
  result = CallWindowProc_(oldlist, hwnd, msg, wparam, lparam) 
  If msg = #WM_RBUTTONDOWN 
    HitInfo.LVHITTESTINFO 
    Hitinfo\pt\x = lparam&$ffff
    HitInfo\pt\y = lparam>>16&$ffff 
    SendMessage_(lv,#LVM_SUBITEMHITTEST,0,@HitInfo) 
    GetNewText(hitinfo\iitem,hitinfo\iSubItem) 
    Debug hitinfo\iitem 
    Debug hitinfo\iSubItem 
  EndIf 
  ProcedureReturn result 
EndProcedure 
**EDIT : altered the code.
I may look like a mule, but I'm not a complete ass.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Thanks, Thanks, Thanks, Thanks, Thanks, Thanks, Thanks, Thanks

You never know why, i thanks you 8)
It's so difficult for me, and apparently so easy for you :oops:

I wish you the most best good day of the word :D
Thanks you very much for your precious help day by day, and the shared of your great knowledge 8)
ImageThe happiness is a road...
Not a destination
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

No, what you did in moving the listicon was upset the (x, y) coordinates being used in the hittest. The #LVM_SUBITEMHITTEST message requires coordinates to be given relative to the listicon's client area itself which is exactly what the #WM_RBUTTONDOWN message provides in it's lParam parameter anyhow! :)
I may look like a mule, but I'm not a complete ass.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Thanks for your explanation 8)
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

I have again a problem :cry:

Thanks to you, i have switched the procedure subclass and that's fine :D
I have also remove the select case, because it's limited to 3 column.

But my new problem, is that, when i click on a empty cell, the selection is big because the variable "hitinfo\iItem" is again at -1 :?
and with this code, i can't write in an empty cell :cry:

Code: Select all

#LVM_SUBITEMHITTEST = #LVM_FIRST + 57
Global oldlist,lv 

Procedure.s GetNewText(item,subitem,xpos)
  
  OpenWindow(1, xpos + 150,DesktopMouseY()+10,260,20,"",#PB_Window_BorderLess) 
  GetWindowRect_(WindowID(1), editrect.rect) 
  ClipCursor_(editrect) 
  CreateGadgetList(WindowID(1)) 
  StringGadget(1,0,0,190,20,"") 
  ButtonGadget(2,190,0,30,20,"OK") 
  ButtonGadget(3,220,0,40,20,"Cancel") 
  SetActiveGadget(1) 
  AddKeyboardShortcut(1,#PB_Shortcut_Return,1) 
  SetGadgetItemColor(0,item,#PB_Gadget_BackColor,RGB(200,200,200),subitem) 
  quit=0 
  
  Repeat 
    ev=WaitWindowEvent() 
      If EventWindow()=1 
      Select ev 
        Case #PB_Event_Menu 
          If EventMenu()=1 
            SetGadgetItemText(0,item,GetGadgetText(1),SubItem) 
            CloseWindow(1) 
            quit = 1 
          EndIf 
        Case #PB_Event_Gadget 
          If EventGadget()=2 
            SetGadgetItemText(0,item,GetGadgetText(1),SubItem) 
            CloseWindow(1) 
            quit = 1      
          ElseIf EventGadget() = 3 
            CloseWindow(1) 
            quit = 1    
          EndIf 
      EndSelect 
   EndIf    
  Until quit 
  
  SetGadgetItemColor(0,item,#PB_Gadget_BackColor,#White,subitem) 
  
  ClipCursor_(0) 
EndProcedure 

Procedure SubClass_LV(hwnd, msg, wparam, lparam) 

 Result = CallWindowProc_(oldlist, hwnd, msg, wparam, lparam) 
 
 If Msg = #WM_RBUTTONDOWN 
  HitInfo.LVHITTESTINFO 
  Hitinfo\pt\x = lparam & $ffff 
  HitInfo\pt\y = lparam >> 16&$ffff 
  SendMessage_(lv, #LVM_SUBITEMHITTEST, 0, @HitInfo) 
  GetNewText(hitinfo\iItem, hitinfo\iSubItem, Hitinfo\pt\x) 
 EndIf 
 
 ProcedureReturn result 
 
EndProcedure 

OpenWindow(0,0,0,640,480,"ListIcon Gadget Mischief: Edit Selected Item",$CF0001) 
CreateGadgetList(WindowID(0)) 
lv = ListIconGadget(0,0,100,640,280,"",0,#PB_ListIcon_GridLines) 
AddGadgetColumn(0,1,"Column 1",210) 
AddGadgetColumn(0,2,"Column 2",210) 
AddGadgetColumn(0,3,"Column 3",215) 

For i = 1 To 12 
  linestr.s = LSet(Str(i),3," ") 
  AddGadgetItem(0, -1, Chr(10)+"Text on Line "+linestr+" in Column 1"+Chr(10)+"Text on Line "+linestr+" in Column 2"+Chr(10)+"Text on Line "+linestr+" in Column 3") 
Next
 
oldlist=SetWindowLong_(lv, #GWL_WNDPROC, @SubClass_LV()) 

Repeat 
  ev = WaitWindowEvent() 
Until ev=#WM_CLOSE 
ImageThe happiness is a road...
Not a destination
Post Reply