?
Solved

TreeView with checkboxes had draw problem

Posted on 2005-03-04
9
Medium Priority
?
1,310 Views
Last Modified: 2007-12-19
Hello,

I use the standard D7 TreeView and if I enable checkboxes

procedure TMyCustomTreeView.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);

    Params.Style := Params.Style or TVS_CHECKBOXES;
end;


a HScrollbar is shown, but the Treeview has no nodes!

If I add the first node the behavoir is normal and HScrollbar is only shown if is it neccesary.

How can I have a normal behavoir from the begin?

regards

William
0
Comment
Question by:SirWinston8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 
LVL 10

Accepted Solution

by:
Jacco earned 2000 total points
ID: 13465794
Here is how I got it working.

Regards Jacco

uses
  CommCtrl;

procedure SetComCtlStyle(Ctl: TWinControl; Value: Integer; UseStyle: Boolean);
var
  Style: Integer;
begin
  if Ctl.HandleAllocated then
  begin
    Style := GetWindowLong(Ctl.Handle, GWL_STYLE);
    if not UseStyle then Style := Style and not Value
    else Style := Style or Value;
    SetWindowLong(Ctl.Handle, GWL_STYLE, Style);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetComCtlStyle(Treeview1, TVS_CHECKBOXES, True);  
end;
0
 

Author Comment

by:SirWinston8
ID: 13466258
Good, one step closer.

But how can I refresh the window if I had nodes in it and toogle the style in runtime?

Regards William
0
 
LVL 10

Expert Comment

by:Jacco
ID: 13466943
Add a call to the protected method RecreateWnd after disabling the checkboxes.

You can call the protected method like this:

type
  TMyTreeView = class(TTreeView);

procedure TForm1.Button3Click(Sender: TObject);
begin
  SetComCtlStyle(Treeview1, TVS_CHECKBOXES, False);
  TMyTreeView(Treeview1).RecreateWnd;
end;

When enabling/disabling you will loose the checks that are set. Look at the source of TListView to see how Delphi saves their state.

Regards Jacco
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:SirWinston8
ID: 13475063
Hi,

your solution does work on a form, but not inside a derived class.

The problem with the HScrollbar appears also if you insert a node:

 - insert a node with too long text put a HScrollbar in the window, this is OK!
 - edit the same node to a shorter text will NOT remove the HScrollbar!!!!!!

 - after you insert a new node the HScrollBar will remove!?!?!

Do you have an explanition for this?

Regards William
0
 

Author Comment

by:SirWinston8
ID: 13475072
I forget!

it seems to me that TTreeview-class does not correct syncronize with the underlaying Windows TreeView?!?!?!
0
 

Author Comment

by:SirWinston8
ID: 13477776
Hi,

I have done any tests.

Following forces, after edit any node, the TreeView to adjust it's ScrollBars.
It works!

procedure TMyCustomTreeView.Edit(const Item: TTVItem);
begin
  inherited Edit(Item);

  if HandleAllocated then
  begin
    Style := GetWindowLong(Handle, GWL_STYLE);
    Style := Style or TVS_NOSCROLL;
    SetWindowLong(Handle, GWL_STYLE, Style);
    Style := Style and not TVS_NOSCROLL;
    SetWindowLong(Handle, GWL_STYLE, Style);
  end;
end;


The same code in this procedure or CreateHandle or CreateWnd does NOTHING!

procedure TMyCustomTreeView.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);

  if FShowCheckBoxes then
    Params.Style := Params.Style or TVS_CHECKBOXES
  else
    Params.Style := Params.Style and not TVS_CHECKBOXES;

  if HandleAllocated then
  begin
    Style := GetWindowLong(Handle, GWL_STYLE);
    Style := Style or TVS_NOSCROLL;
    SetWindowLong(Handle, GWL_STYLE, Style);
    Style := Style and not TVS_NOSCROLL;
    SetWindowLong(Handle, GWL_STYLE, Style);
  end;

end;

Do you have any idea?

Regards William

0
 
LVL 10

Expert Comment

by:Jacco
ID: 13483833
CreateParams is only call once when creating the control (and when a RecreateWnd is issued). Edit is called every time a label is edited.

Can't figure out why the scrollbar stays and when it disappears...

Regards Jacco
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question