View previous topic :: View next topic |
Author |
Message |
paul44 Expert Cheater
Reputation: 2
Joined: 20 Jul 2017 Posts: 193
|
Posted: Sun May 18, 2025 10:47 am Post subject: Checklistbox: OnItemClick fn does not get saved/accepted |
|
|
image: see here [ https://ibb.co/album/NdwCkt ]
I can't seem to assign a function to 'OnItemClick': as soon as i leave the field, it gets removed.
Note: i currently solve it by parkouring the complete list, and find the 'Selected' in question
ps: tried all CE vs up to 7.5
ps2: i assume that this particular event 'kicks in' the moment one clicks on any list_entry (which gets then selected in the process). Ie clicking on any other location within the listbox (incl checkboxes) has no effect (iow the fn will then not be called) ?!
|
|
Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 35
Joined: 16 Feb 2017 Posts: 1481
|
Posted: Sun May 18, 2025 5:37 pm Post subject: |
|
|
Here's an idea;
Code: | -- Destroy existing form if it exists
if myForm then myForm.Destroy() myForm=nil end
-- Create a new form
myForm = createForm()
myForm.Caption = "Select Line: ..."
myForm.Width = 300
myForm.Height = 400
-- Create a CheckListBox inside the form
checkListBox = createCheckListBox(myForm)
checkListBox.Width = 250
checkListBox.Height = 200
checkListBox.Left = 25
checkListBox.Top = 50
-- Add items to CheckListBox
for i = 0, 3 do
checkListBox.Items.add("Item " .. i)
end
----------------------------------------
-- Functions to handle selection changes
function OnChange_d0(stt)
if stt==1 then print(stt, "Hack ON!") else print(stt, "Hack OFF!") end
end
function OnChange_d1(stt)
if stt==1 then print(stt, "Hack ON!") else print(stt, "Hack OFF!") end
end
function OnChange_d2(stt)
if stt==1 then print(stt, "Hack ON!") else print(stt, "Hack OFF!") end
end
function OnChange_d3(stt)
if stt==1 then print("Hack ON!") else print("Hack OFF!") end
end
local opts = 0 -- Option variable to manage click behavior
-- Function to handle selection changes based on click type
function onSelectionChange(sender)
local index = sender.ItemIndex
if index >= 0 then
-- If checkbox is clicked, maintain its state
if opts == 1 then
sender.Checked[index] = sender.Checked[index]
else
-- If item text is clicked, toggle checkbox state
sender.Checked[index] = not sender.Checked[index]
end
-- Call corresponding OnChange_d function
local rn = _G["OnChange_d" .. index]
local isState = sender.Checked[index] and 1 or 0 or nil
rn(tonumber(isState))
end
opts = 0 -- Reset option variable
end
-- Triggered only when clicking on the checkbox
checkListBox.OnClickCheck = function(s) opts=1 onSelectionChange(s) end
-- Triggered only when clicking on the item text, does not affect checkbox
checkListBox.OnClick = function(s) if opts~=1 then onSelectionChange(s) end end |
_________________
|
|
Back to top |
|
 |
paul44 Expert Cheater
Reputation: 2
Joined: 20 Jul 2017 Posts: 193
|
Posted: Wed May 21, 2025 11:48 am Post subject: |
|
|
@AylinCE: thx for that code; i will try '.OnClick' probably this weekend; and report back...
(problem w/ checkListBox, is no/minimal info; let alone about them event_functions)
|
|
Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 35
Joined: 16 Feb 2017 Posts: 1481
|
Posted: Thu May 22, 2025 11:17 am Post subject: |
|
|
I think it depends on the frequency of use; It is a control left to the Supply - Demand option.
On the other hand, the "OnClick" event alone would be an insufficient solution.
OnClick only makes selections in the row and works independently of the box marking. (This would be like a normal "ListBox".)
"OnClickCheck", on the other hand, only follows the box marking or unmarking.
If both events are used, "OnClick" will return the valid result.
The code above uses both events without any problems.
You can add a row or something else to "rn(tonumber(isState))" and send it to the function.
Remember; In cases where a selection does not affect the other selections (If multiple selections can be made), it can be used in "ScrollBar" and "CheckBox" in it.
However, depending on the necessity, the decision is yours.
_________________
|
|
Back to top |
|
 |
|