Delphi tree view with checkboxes: sometimes the checkboxes are invisible
I have a problem. I have a TTreeview descendant that shows checkboxes just fine on my own computer and all other I have tested myself.
TVS_CHECKBOXES
is set using SetWindowLong
. In the Loaded
method I set开发者_StackOverflow/maintain checked states with StateIndex := 2;
, Item.State := TVIS_CHECKED
, etc.
So far so good. But now a person contacted me where the treeview checkboxes does not show at all on his WindowsXP SP3. (He even provided me with a screenshot.) From the program behavior, I can say the default-checked-nodes are working since program otherwise from customer description behaves like expected.
I have not been able to find similar symptoms described anywhere. All computers I have tested on, it works well. But the screenshot from the customer shows that there's a problem :(
My best guess is that it's some RecreateWnd
that on some systems reset the treeview checkbox mode?
My options for testing is limited since I can not reproduce problem on my own computers, so would like to know if others have other suggestions I can try before I send new beta code to the person who's system seems to be hiding the treeview checkboxes?
Setting this style in an overriden CreateWnd
could be too late according to the documentation:
If you want to use this style, you must set the TVS_CHECKBOXES style with SetWindowLong after you create the treeview control, and before you populate the tree. Otherwise, the checkboxes might appear unchecked, depending on timing issues.
Now, this seems like a small egg-and-chicken dilemma, because the VCL does not provide a real solution for this exact moment in time. Setting this style before the inherited CreateWnd call is not possible because there is no handle yet. But after the inherited call, the tree might already be populated due to recreation. (The VCL streams the nodes back in TCustomTreeView.CreateWnd
).
But since this just looks like a simple style modification, you could (also) try override CreateParams
and add this flag to Params.Style
which works just as fine here.
procedure TMyTreeView.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style := Params.Style or TVS_CHECKBOXES;
end;
Though I cannot reproduce the problem either. And nodes appearing unchecked does not match being unvisible at all, so I really wonder this would fix it.
精彩评论