View Issue Details

IDProjectCategoryView StatusLast Update
0003361JEDI VCL00 JVCL Componentspublic2006-01-05 08:02
Reporterhansverlouw3Assigned Toobones 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.00 
Target VersionFixed in Version3.20 
Summary0003361: Get and set checkbox value in TJvTreeView
DescriptionWhen a checkbox is checked, I want to check all its children as well.
But I cannot determine if a checkbox has changed.
Isn't there a property missing?

I tested with

procedure TfrmMain.JvTreeView1MouseDown(Sender: TObject;
    Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
    if TJvTreeNode(JvTreeView1.GetNodeAt(x,y)).checked then
        Panel1.Color := clGreen
    else
        Panel1.Color := clRed;
end;
TagsNo tags attached.

Activities

hansverlouw3

2005-12-13 05:01

reporter   ~0008214

Found the solution myself ;-)
Use TJvCheckTreeView in stead of TJvTreeView.
TJvCheckTreeView has an event OnToggled.
By the way, note that it only behaves ok when
CheckBoxOptions.Style = cbsJVCL.

So to cascade checkbox values on toggling a node, use something like this:

procedure TfrmMain.JvTreeView1Toggled(Sender: TObject; Node: TTreeNode);
var
  i: integer;
  Child: TTreeNode;
begin
  Child := Node.getFirstChild;
  for i := 0 to Node.Count - 1 do
  begin
    TJvTreeNode(Child).Checked := TJvTreeNode(Node).Checked;
    Child := Node.GetNextChild(Child);
  end;
end;

hansverlouw3

2005-12-13 05:31

reporter   ~0008215

A recursive implementation of the procedure in the previous note:

procedure TfrmMain.CheckCascading(Node: TTreeNode);
var
  i: integer;
  Child: TTreeNode;
begin
  Child := Node.getFirstChild;
  for i := 0 to Node.Count - 1 do
  begin
    TJvTreeNode(Child).Checked := TJvTreeNode(Node).Checked;
    CheckCascading(Child);
    Child := Node.GetNextChild(Child);
  end;
end;


procedure TfrmMain.JvTreeView1Toggled(Sender: TObject; Node: TTreeNode);
begin
  CheckCascading(Node);
end;

Issue History

Date Modified Username Field Change
2005-12-12 10:08 hansverlouw3 New Issue
2005-12-13 05:01 hansverlouw3 Note Added: 0008214
2005-12-13 05:31 hansverlouw3 Note Added: 0008215
2006-01-05 08:02 obones Status new => resolved
2006-01-05 08:02 obones Resolution open => fixed
2006-01-05 08:02 obones Assigned To => obones
2010-10-30 15:52 outchy Relationship added has duplicate 0005386
2010-10-30 15:53 outchy Relationship deleted has duplicate 0005386