DRAG AND DROP

Just starting out? Need help? Post your questions and find answers here.
loulou2522
Enthusiast
Enthusiast
Posts: 504
Joined: Tue Oct 14, 2014 12:09 pm

DRAG AND DROP

Post by loulou2522 »

Hello all,
This is my problem:
I have two lists
A and B
in A i have "Toto", "TITI", "TATA"
in b i have "TRAE", "TITI",tatan".
I want to manually drag and drop the texts common between list A and list B, in this case select "TITI" from the first list and drop it on the "TITI" of the second list and make sure that this word is associated with the word in the first list. Can someone guide me in the design of this module?
Thank you in advance

In fact what I want is to be able to point manually from the first list the common text between the two lists.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: DRAG AND DROP

Post by TI-994A »

loulou2522 wrote:...manually drag and drop the texts common between list A and list B, in this case select "TITI" from the first list and drop it on the "TITI" of the second list and make sure that this word is associated with the word in the first list...
If understood correctly:

Code: Select all

Enumeration
  #mainWindow
  #list1
  #list2
EndEnumeration

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#mainWindow, #PB_Ignore, #PB_Ignore, 600, 400, 
           "Drag & Drop Text Matching", wFlags)
TextGadget(#PB_Any, 20, 10, 200, 30, "List 1")
TextGadget(#PB_Any, 320, 10, 200, 30, "List 2")
ListViewGadget(#list1, 10, 40, 280, 350)
ListViewGadget(#list2, 310, 40, 280, 350)
EnableGadgetDrop(#list1, #PB_Drop_Text, #PB_Drag_Copy)
EnableGadgetDrop(#list2, #PB_Drop_Text, #PB_Drag_Copy)

AddGadgetItem(#list1, -1, "apples")
AddGadgetItem(#list1, -1, "oranges")
AddGadgetItem(#list1, -1, "grapes")
AddGadgetItem(#list1, -1, "bananas")
AddGadgetItem(#list1, -1, "peaches")
AddGadgetItem(#list1, -1, "mangoes")
AddGadgetItem(#list1, -1, "strawberries")
AddGadgetItem(#list2, -1, "bananas")
AddGadgetItem(#list2, -1, "strawberries")

Repeat
  
  Select WaitWindowEvent()   
      
    Case #PB_Event_CloseWindow
      appQuit = #True        
      
    Case #PB_Event_Gadget       
      Select EventGadget()          
        Case #list1, #list2          
          Select EventType() 
            Case #PB_EventType_DragStart
              sourceGadget = EventGadget()
              selectedIndex = GetGadgetState(EventGadget())
              selectedText$ = GetGadgetItemText(EventGadget(), selectedIndex)
              DragText(selectedText$)                                           
          EndSelect
      EndSelect
      
    Case #PB_Event_GadgetDrop
      dropGadget = EventGadget()
      If dropGadget <> sourceGadget
        For i = 0 To CountGadgetItems(dropGadget)
          If GetGadgetItemText(dropGadget, i) = selectedText$
            msg$ = selectedText$ + " exists in list " + Str(dropGadget)
            MessageRequester("Drag & Drop", msg$)
            matchFound = #True
            Break          
          EndIf
        Next i
        If Not matchFound
          AddGadgetItem(dropGadget, -1, EventDropText())
          RemoveGadgetItem(sourceGadget, selectedIndex)    
        EndIf
        matchFound = #False
      EndIf
      
  EndSelect  
  
Until appQuit
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
loulou2522
Enthusiast
Enthusiast
Posts: 504
Joined: Tue Oct 14, 2014 12:09 pm

Re: DRAG AND DROP

Post by loulou2522 »

In order to be clearer in my explanation, let's take an accounting example: I have recorded an accounting entry in my computer system and on receipt of the account statement by the bank I want to be able to point to this entry with the receipt from the bank.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: DRAG AND DROP

Post by TI-994A »

loulou2522 wrote:...point to this entry with the receipt from the bank.
So, essentially, to drag an entry from your bank's electronic statement (viewed through an external application) over to a list in PureBasic, to find a match?

Code: Select all

Enumeration
  #mainWindow
  #list1
  #list2
EndEnumeration

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#mainWindow, #PB_Ignore, #PB_Ignore, 600, 400, 
           "Drag & Drop Text Matching", wFlags)
TextGadget(#PB_Any, 20, 10, 200, 30, "Bank Statement")
TextGadget(#PB_Any, 320, 10, 200, 30, "Personal Records")
ListViewGadget(#list1, 10, 40, 280, 350)
ListViewGadget(#list2, 310, 40, 280, 350)
EnableGadgetDrop(#list1, #PB_Drop_Text, #PB_Drag_Copy)
EnableGadgetDrop(#list2, #PB_Drop_Text, #PB_Drag_Copy)

AddGadgetItem(#list1, -1, "31DEC20#789")
AddGadgetItem(#list1, -1, "19JAN21#456")
AddGadgetItem(#list1, -1, "28JAN21#123")
AddGadgetItem(#list2, -1, "31DEC20#789")
AddGadgetItem(#list2, -1, "02JAN21#123")
AddGadgetItem(#list2, -1, "15JAN21#666")
AddGadgetItem(#list2, -1, "19JAN21#456")
AddGadgetItem(#list2, -1, "22JAN21#789")
AddGadgetItem(#list2, -1, "28JAN21#123")
AddGadgetItem(#list2, -1, "30JAN21#999")

Repeat
  
  Select WaitWindowEvent()   
      
    Case #PB_Event_CloseWindow
      appQuit = #True        
      
    Case #PB_Event_Gadget       
      Select EventGadget()          
        Case #list1, #list2          
          Select EventType() 
            Case #PB_EventType_DragStart
              sourceGadget = EventGadget()
              selectedIndex = GetGadgetState(EventGadget())           
              selectedText$ = GetGadgetItemText(EventGadget(), selectedIndex)
              DragText(selectedText$)                                           
          EndSelect
      EndSelect
      
    Case #PB_Event_GadgetDrop
      dropGadget = EventGadget()
      If dropGadget <> sourceGadget
        dropText$ = EventDropText()
        For i = 0 To CountGadgetItems(dropGadget)
          If GetGadgetItemText(dropGadget, i) = dropText$
            SetActiveGadget(dropGadget)
            SetGadgetState(dropGadget, i)            
            Break              
          EndIf
        Next i
      EndIf
      sourceGadget = -1
      
  EndSelect  
  
Until appQuit
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
loulou2522
Enthusiast
Enthusiast
Posts: 504
Joined: Tue Oct 14, 2014 12:09 pm

Re: DRAG AND DROP

Post by loulou2522 »

Thanks TI_99A
That's exactly what i want. For the treamtment i have to programm special treatment but know i have the strucutre of the programm
Have a nice day
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: DRAG AND DROP

Post by TI-994A »

loulou2522 wrote:...That's exactly what i want.
Glad to hear it. The drag-&-drop works between the two list views, but it also accepts text drops from external applications.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply