|
Post by xxgeek on Jul 25, 2022 1:53:53 GMT
Is there a known issue with singleclickselect not working as intended?
I'm using a listbox and when clicked text is supposed to appear in a texteditor. It works sometimes, other times no. Listing gets highlighted, but the text doesn't appear in the texteditor. If I double click, the text does appear. Other times a single click is sufficient
What is going on? Anyone?
Could it be due to reloading of the array of the listbox? Do I need to restate the singleclickselect after reloading a new array?
|
|
|
Post by jarych on Jul 25, 2022 3:53:19 GMT
Is there a known issue with singleclickselect not working as intended? I'm using a listbox and when clicked text is supposed to appear in a texteditor. It works sometimes, other times no. Listing gets highlighted, but the text doesn't appear in the texteditor. If I double click, the text does appear. Other times a single click is sufficient What is going on? Anyone? Could it be due to reloading of the array of the listbox? Do I need to restate the singleclickselect after reloading a new array? Maybe for better help to you I ask a question. Is your program being coded to have either of two arrays for one listbox?
|
|
|
Post by jarych on Jul 25, 2022 4:36:19 GMT
I hoped to help, but I cannot so your question makes two of us.
Probably same problem as yours but not know:
takenut$="" dim nut$(25) nutlist$="peanut cashew walnut pecan hazelnut almond coconut pinenut filbert spanishpeanut"
n=0 tp$="?" while tp$<>"" n=n+1 tp$=word$(nutlist$,n) nut$(n)=tp$ wend
nomainwin
WindowWidth = 550 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
listbox #main.listbox1, nut$(, [listbox1DoubleClick], 38, 46, 128, 200 texteditor #main.texteditor2, 254, 46, 256, 200 menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "listbox and singleclickselect, for xxgeek" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10" print #main.listbox1,"singleclickselect"
wait
[quit.main] Close #main END
[listbox1DoubleClick] 'Perform action for the listbox named 'listbox1' 'Insert your own code here notice "REACHED YES, SINGLECLICKED" print #main.listbox1,"selection? ";takenut$ print #main.texteditor2,"!contents ";takenut$ wait
|
|
|
Post by jarych on Jul 25, 2022 4:43:11 GMT
MAYBE this helps you... as a variable, takenut$ should inside the quotes.
takenut$="" dim nut$(25) nutlist$="peanut cashew walnut pecan hazelnut almond coconut pinenut filbert spanishpeanut"
n=0 tp$="?" while tp$<>"" n=n+1 tp$=word$(nutlist$,n) nut$(n)=tp$ wend
nomainwin
WindowWidth = 550 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
listbox #main.listbox1, nut$(, [listbox1DoubleClick], 38, 46, 128, 200 texteditor #main.texteditor2, 254, 46, 256, 200 menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "listbox and singleclickselect, for xxgeek" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10" print #main.listbox1,"singleclickselect"
wait
[quit.main] Close #main END
[listbox1DoubleClick] 'Perform action for the listbox named 'listbox1' 'Insert your own code here notice "REACHED YES, SINGLECLICKED" print #main.listbox1,"selection? takenut$" print #main.texteditor2,"!contents takenut$" wait [/code
|
|
|
Post by xxgeek on Jul 25, 2022 5:31:13 GMT
Thanks for the effort jarych.
To answer your first question. I'm using one listbox and one array, but loading them with ten different lists.
Each list is selected using a radio button. When a radio button is clicked the corresponding list appears. When an item in the list is clicked, it gets highlighted, and it's data appears in the texteditor. But not always. Sometimes it takes a double click to have the data appear even though the item in the list gets highlighted.
|
|
|
Post by Rod on Jul 25, 2022 7:40:20 GMT
Its not so much an issue as just the way it works. The event is a "change" event. So if you click the same item no event fires. To be sure to force a selection each click you need to clear the text field after the initial selection. See the change here in the [select] code.
'lets put eight items into a large array to allow for later additions 'in this code we will ignore cbarray$(0) as the combobox will reserve 'that item for its own use dim cbarray$(100)
'now we need a variable to track how many items we have loaded in the array items=8
'here is our initial array, note that we start from cbarray$(1) as does word$(index) 'and so to the combobox index. cbarray(0) is ignored. collection$="aone btwo cthree dfour efive fsix gseven height" for w=1 to items cbarray$(w)=word$(collection$,w) next sort cbarray$(,1,items
'nomainwin WindowWidth = 550 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
combobox #main.cb1, cbarray$(, [select], 38, 46, 144, 100 button #main.badd, "Add", [add], UL, 38, 116, 122, 25 button #main.bremove, "Remove Selected", [remove], UL, 38, 156, 122, 25 open "combobox study" for window as #main #main "trapclose [quit.main]"
wait
[quit.main] Close #main END
[select] 'fetch what has been selected #main.cb1 "contents? picked$" notice "Event fired for ";picked$ #main.cb1 "select 0" wait
[add] 'get what is in the combobox text field 'add it to the end of cbarray$( , re-sort and reload 'then set the text field #main.cb1 "contents? picked$" items=items+1 cbarray$(items)=picked$ sort cbarray$(,1,items #main.cb1 "reload" #main.cb1 "select ";picked$ wait
[remove] 'get the index of the item to delete 'compress the array to remove it from cbarray$( 're-sort and reload 'then blank the text field #main.cb1 "selectionindex? s" for i=s to items cbarray$(i) = cbarray$(i+1) next items=items-1 sort cbarray$(,1,items #main.cb1 "reload" #main.cb1 "selectindex 0" wait
|
|
|
Post by jarych on Jul 25, 2022 9:31:42 GMT
One will find upon rechecking xxgeek's initial posting about this topic, of a question about using singleclick select for a listbox, and what user selects is not always written into a referenced texteditor control.
|
|
|
Post by Rod on Jul 25, 2022 10:38:01 GMT
Well it's the same answer. Singleclick on the same choice will not create a new change event, in a listbox doubleclick will. Or you can clear the selection with select 0, then singleclick will work again.
'Sample program. Pick a contact status options$(0) = "Cold Contact Phone Call" options$(1) = "Send Literature" options$(2) = "Follow Up Call" options$(3) = "Send Promotional" options$(4) = "Final Call" listbox #status.list, options$(), [selectionMade], 5, 35, 250, 90
WindowWidth = 270 : WindowHeight = 180 open "Select a contact status" for window as #status #status.list "singleclickselect" #status "trapclose [quit]" wait
[selectionMade] #status.list "selection? selection$" notice selection$ + " was chosen" #status.list "select 0" wait
[quit] close #status end
|
|
|
Post by xxgeek on Jul 25, 2022 16:24:48 GMT
#status.list "select 0" or in my case it was #main.keys "select 0"
It's like a reset button. That seems to have fixed the problem. One well placed line of code ends a long time headache. I've been trying to figure that out for quite some time. I'll keep playing around with it to see if it happens anywhere else in my program. Might need it more than once.
Thanks Rod.
|
|
|
Post by jarych on Jul 25, 2022 17:15:39 GMT
xxgeek, you were talking about printing to a texteditor control. What fixed what is not clear. This was found in your question posting:
I tried making a simple example myself but found only that anything I picked from listbox displayed in only one spot on the texteditor, which may in fact be what supposed to happen. Not clear if "singleclickselect" codeline changes anything or not. (I did not save my sample program and did not post it either).
|
|
|
Post by xxgeek on Jul 25, 2022 17:32:09 GMT
That is what was happening before applying Rod's fix. Sometimes, not always, the listbox item got highlighted, but no text appeared in the text editor. Needed to double click for text to appear.
So far, after applying Rod's fix. the item in listbox is highlighted and the text always appears now in texteditor as intended (one click).
After re-loading the listbox I used #main.keys "select 0" and it all works properly.
|
|
|
Post by xxgeek on Jul 25, 2022 18:37:38 GMT
Ok, I got a new problem. index 0 out of bounds and then crashes my program.
So I tried #main.keys, "select 1" instead of #main,keys, "select 0"
So far working great. I'll post back if problems occur.
|
|
|
Post by Rod on Jul 25, 2022 19:15:18 GMT
Select 0 is safe. Select 1 will always select the first item on the list and its selection event will not fire without a doubleclick. We are jumping about a bit. Use the debugger to see what line the code fails at. Neither should you be using #main.keys, "select 0". The syntax is now PRINT #main.keys, "select 0" or #main.keys "select 0" If you drop the PRINT also drop the ,
index out of bounds is an error associated with syntax not array indexes, if the array index is wrong Just BASIC will tell you. So you likely have something wrong with a code line and an argument is missing or misplaced. Run in debug and the code should stop on the offending line.
|
|
|
Post by xxgeek on Jul 25, 2022 23:24:11 GMT
Ok, I dropped the , and so far so good. Back to using #main.keys "select 0" and all seems well.
Hope I'm not speaking too soon again. Will post again if problems.
It's great having people here who know the ins and outs of Just Basic, and willing to help out in record time.
Thanks again Rod, and jarych
|
|