Forum > Lazarus Extra Components
Virtual tree with checkbox header and column
JD:
Hello everyone,
I have a virtual tree with an ID column with checkboxes and I want to select/deselect ALL the IDs in the list by selecting/deselecting the checkbox in the header (see screenshot).
Does anyone know how I can get this done?
Thanks,
JD
balazsszekely:
Hi JD,
--- Quote ---I have a virtual tree with an ID column with checkboxes and I want to select/deselect ALL the IDs in the list by selecting/deselecting the checkbox in the header (see screenshot).
Does anyone know how I can get this done?
--- End quote ---
I suppose you meant check/uncheck all, insted of select/deselect. Please try 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 TForm1.CheckUncheckNodes(const Checked: Boolean);var Node: PVirtualNode;begin VDT.BeginUpdate; try Node := VDT.GetFirst; while Assigned(Node) do begin if Checked then VDT.CheckState[Node] := csCheckedNormal else VDT.CheckState[Node] := csUncheckedNormal; Node := VDT.GetNext(Node); end; finally VDT.EndUpdate; end;end; procedure TForm1.CheckBox1Click(Sender: TObject);begin CheckUncheckNodes(CheckBox1.Checked);end;
JD:
Hi there GetMem,
Thanks a lot for the code. However I needed to clarify something. In the image, the ID is header row in the second column in the VirtualTree. So I want to check/uncheck the checkbox in the header of the virtualtree and automatically check/uncheck all the rows in the virtualtree.
I hope my description is clearer.
JD
JD:
I want to put GetMem's code in an eventhandler for checking the box in the header of the ID column.
I think it will work that way.
Any ideas how I can do that?
JD
balazsszekely:
@JD
There is an OnHeaderClick event for VirtualStringTree, using the code from my previous post:
--- 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 TForm1.VDTHeaderClick(Sender: TVTHeader; HitInfo: TVTHeaderHitInfo);begin if (hhiOnCheckbox in HitInfo.HitPosition) and (HitInfo.Column = 1) then //for the second, "ID" column begin if Sender.Columns[HitInfo.Column].CheckState = csCheckedNormal then CheckUncheckNodes(True) else CheckUncheckNodes(False); end;end;
Navigation
[0] Message Index
[#] Next page