We help IT Professionals succeed at work.

How do I add checkbox support to VirtualStringTree to any of the nodes i choose? . eg. Root, node, the third node, fifth node or whatever.

Alpha_AI
Alpha_AI asked
on
3,644 Views
Last Modified: 2012-08-14
Hello,

How do I add a checkbox to a node in a virtualstringtree.
It mustnt be just root. It has to be any node that I choose.

I thought it might be something like this

procedure TForm1.BitBtn6Click(Sender: TObject);
var
  Data :PNodeData;
  Node :PVirtualNode;
begin
Node := VtClips.GetFirst;
while Node <> nil do
  begin
  Data := VtClips.GetNodeData(Node);
  if Data.Meaning4 = 'Ben' then
   begin
   VtClips.CheckType[Node];
   break;
   end;
  Node := VtClips.GetNExt(node);
end;
end;

however that doesnt work.

The other thing also is my type has mostly strings

type PNodeData=^TNodeData;
  TnodeData= record
  DictionaryWord:String;
  Type1 : string;
  Meaning1:String;
  Meaning2:String;
  Meaning3:String;
  Meaning4:String;

and since checkbox seems like it is a boolean value
i was thinking it might be like this

type PNodeData=^TNodeData;
  TnodeData= record
  DictionaryWord:String;
  Type1 : string;
  Meaning1:String;
  Meaning2:String;
  Meaning3:String;
  Meaning4: boolean;

however the  CellText in the GetText event is of type WideString not boolean.

I was able to implement a editor with ComboBox and DateTimePicker functionality. Those works fine and I can
choose to select which columns I want them in no problems there.

I thought that maybe I could create a TCheckBox the same way that i added ComboBox and DateTimePicker but I think it is the wrong way to go
I dont know.

The SoftGems forums say

Q: I try to activate check box support. I Turned toCheckSupport in Misc. options to true and selected one of CheckImageKinds but nothing happened. What else should I do to activate checkboxes?

A: Set a check style for each node you want to have one. See VT.CheckStyle[].

Any clues?

Ben
Comment
Watch Question

TheRealLokiSenior Developer
CERTIFIED EXPERT

Commented:
I do it manually,
I use the GetImageIndex event
and i store the check value inside the node's PLinkData record
eg.

procedure TFrame_DefinitionRuleBlocks.VST_RightMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  HitInfo: THitInfo;
  Data, OtherData: PLinkData;
  pt: TPoint;
  s: string;
begin
  pt := vst_right.ScreenToClient(mouse.CursorPos);
  vst_right.GetHitTestInfoAt(pt.x, pt.y, true, HitInfo);
  if assigned(hitinfo.HitNode) then
  begin
    Data := vst_right.GetNodeData( hitinfo.HitNode );
    case hitinfo.HitColumn of
     col_Recurring:
      begin
         if ssRight in Shift then
         begin
           Data.Rule.Recurring := not Data.Rule.Recurring;
           (sender as TVirtualStringTree).ReinitNode(hitinfo.HitNode, True);
           (sender as TVirtualStringTree).Repaint;
         end;
      end;
...
etc...

I'm not saying this is the correct way to do it, but it's how i do it :-)

Author

Commented:
can you show me what your Plinkdata record looks like?

TheRealLokiSenior Developer
CERTIFIED EXPERT

Commented:
// for virtual trees
type
  PLinkData = ^TLinkData;
  TLinkData = record
    Rule: TRuleBlock;
    OtherNode: PVirtualNode;  // this is only used because i synchronize 2 trees (tree style, and listview style) - this is explained in the treeview demos btw
    Instance: integer; // not needed...
  end;

Rule is just an object like
type TRuleBlock = class(TObject)
public
  Recurring: boolean;
  displayname: string;
....etc...
end;
TheRealLokiSenior Developer
CERTIFIED EXPERT

Commented:
and here's the imageindex portion

procedure TFrame_DefinitionRuleBlocks.VST_RightGetImageIndex(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
  var Ghosted: Boolean; var ImageIndex: Integer);
var
  Data: PLinkData;
begin
  Data := Sender.GetNodeData(Node);
  ImageIndex := ii_Blank;
  case Column of
    col_Recurring: if Data.Rule.Recurring then ImageIndex := ii_Recurring;
    col_Trash: if Data.Rule.Trash then ImageIndex := ii_Trash;
  end;
end;

Author

Commented:
Is there a way to center the image in the node.

procedure TForm1.MyVirtualStringTree1GetImageIndex(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
  var Ghosted: Boolean; var ImageIndex: Integer);
var
  Data: PNodeData;
begin
  Data := Sender.GetNodeData(Node);
  ImageIndex := 0; //Blank;
  case Column of
    8:
   if Data.CheckBlock = nil then
    ImageIndex := 9;
  end;
end;

At this stage all of the nodes in column 8 will have checkboxes
however I need the image to be centered
Is there way to do this. In column there is no text whatsoever just a checkbox.
I also noticed that you use ii_Recurring and ii_trash and ii_blank, are those constants?

Ben
TheRealLokiSenior Developer
CERTIFIED EXPERT

Commented:
yes, they are constances
ii_blank = 0, ii_recurring = 1, ii_trash = 2. these just match up with my TImageList to make things easy for me
Same as col_recurring = the column number

There are some margin properties, but I'm away from my code atm, I'll see if I can check later
Senior Developer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thankyou very much for your time.
Your comments have help big time.

Ben

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.