带复选框的Delphi树视图:有时复选框不可见 [英] Delphi tree view with checkboxes: sometimes the checkboxes are invisible

查看:156
本文介绍了带复选框的Delphi树视图:有时复选框不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题。我有一个TTreeview后代,它在我自己的计算机上以及我自己测试过的所有其他命令上都显示了复选框。

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 是使用 SetWindowLong 设置的。在 Loaded 方法中,我使用 StateIndex:= 2; Item设置/维护检查状态状态:= TVIS_CHECKED ,等等。

TVS_CHECKBOXES is set using SetWindowLong. In the Loaded method I set/maintain checked states with StateIndex := 2;, Item.State := TVIS_CHECKED, etc.

到目前为止很好。但是现在有人联系我,他的WindowsXP SP3的树视图复选框根本不显示 。 (他甚至为我提供了一个屏幕截图。)从程序行为上,我可以说默认检查节点正在运行,因为从客户的角度来看,程序的行为与预期的一样。

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 :(

我最好的猜测是它是某些 RecreateWnd 在某些系统上重置树视图复选框模式?

My best guess is that it's some RecreateWnd that on some systems reset the treeview checkbox mode?

我的测试选项有限,因为我无法在自己的计算机上重现问题,所以想知道其他人是否还有其他问题在将新的Beta代码发送给系统似乎正在隐藏树视图复选框的人之前,我可以尝试一些建议?

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?

推荐答案

设置此项根据 CreateWnd 中的样式可能为时已晚vs.85%29.aspx rel = nofollow>文档

Setting this style in an overriden CreateWnd could be too late according to the documentation:


如果要使用此样式,您必须在创建树状视图控件后之后,并在之前中填充树,然后使用SetWindowLong设置TVS_CHECKBOXES样式,否则,该复选框可能会被取消选中

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.

现在,这似乎是一个小小的鸡蛋和鸡肉的难题,因为VCL并未提供真正及时的解决方案。由于尚无句柄,因此无法在继承的CreateWnd调用之前设置此样式。但是在继承调用之后,由于重新创建,树可能已经被填充。 (VCL在 TCustomTreeView.CreateWnd 中流回节点。)

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).

但是因为这看起来像一个简单的样式修改,您也可以尝试覆盖 CreateParams 并将此标志添加到 Params.Style ,在这里也可以正常使用。

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.

这篇关于带复选框的Delphi树视图:有时复选框不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆