Forum > LCL

Tchecklistbox question

(1/2) > >>

rwebb616:
Is there a way to differenciate between the user clicking the checkbox vs just selecting something in the list? 

I am using a checklist box right now and I put a on-click procedure to make the selections easier so if you click any item it will reverse the checked state of the item.  The problem is if I click on the checkbox itself it will for example turn on and then back off or off and then back on depending on it's state because on itemclick is running as is on click.

Any way to tell if it's an item click vs selection?
Rich

Handoko:

--- Quote from: rwebb616 on May 19, 2021, 04:18:57 am ---I put a on-click procedure to make the selections easier so if you click any item it will reverse the checked state of the item.

--- End quote ---

You don't need to write code for the OnClick event to reverse the state. TCheckListBox will do it automatically for you.

Or maybe I didn't fully understand your explanation.

Can you explain more or perhaps provide a simplified demo that can show us the issue?

rwebb616:
I'm sorry ... I wasn't clear..

I need to check these relatively fast and having to have the mouse directly on the checkbox was problematic so I had coded the on-click event to check or uncheck the box so all I had to do was click the item rather than being right on the checkbox.. but then I had the unintended behavior that when I DO click the checkbox it reverses whatever state so if I click to check it, it checks with the item selection event and then the checkbox unchecks because the checkbox was clicked. 

I just got it sorted though .. Also I forgot to mention that I can only select up to 6 items.  I did this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TfMainForm.clbCategoriesClick(Sender: TObject);var  index:integer;  i:integer;  checked:integer;begin  checked:=0;  index := clbcategories.itemindex;  clbCategories.Checked[index]:=not clbCategories.Checked[index];  for i:=0 to clbcategories.Count -1 do begin    if clbCategories.Checked[i] then inc(checked);  end;  if checked > options.maxcategories then begin  MessageDlg('Error','You can only select up to ' + options.maxcategories.tostring + ' categories!',mtError,[mbOK],'');  if clbCategories.checked[Index] then    clbCategories.Checked[Index]:=not clbCategories.checked[Index];  end;end;  
and I assigned this to two events - onclick and onclickcheck.  Because it runs the same code the checkbox reverses state I guess 3 times.  Once for the actual check being clicked, then once for each event. Ultimately it ends up in the state I want it to be in so now I can click either the checkbox or the item and it will limit me to 6 categories.

Rich

Handoko:
I tested your code on both Windows and GTK2, I saw the problem. That issue does not happen on Linux GTK2.

Give me some time, I am working on it.

rwebb616:

--- Quote from: Handoko on May 19, 2021, 05:05:15 am ---I tested your code on both Windows and GTK2, I saw the problem. That issue does not happen on Linux GTK2.

Give me some time, I am working on it.

--- End quote ---

The code I posted is actually working for what I'm doing - or do you mean the original problem I posted about?

Rich

Navigation

[0] Message Index

[#] Next page

Go to full version