Help with an application that use VirtualTreeView

I have downloaded Virtual TreeView at http://virtualtreeview.delphi-gems.com/VT.php.

Now I like to create an simple application that works like this.

I want the treeview to look like an listview where I can edit the cells. So:

When I start the application I want the cursor to stay in the first cell (top left cell) in edit mode. When I have typed an article number in that cell and hit enter I want a Query to be done.
(select * from articles)

And a object created and added to the Data pointer of the TreeView
(Like this;

ThisArticle.description := qry.FieldByName('description');
ThisArticle.Quantity:= 1;
ThisArticle.Price := qry.FieldByName('price');

Then I want the Cell number 2 to contain the descripton, the cell nr 3 the number 1, and the Cell 4 the price and the cell 5 the Quantity * the Price.

Now I want the cursor to be moved to cell 3 in edit mode so I can change the Quantity. When I hit enter I want it to go to
the first cell in the next row and stand in edit mode to do the same again.

The problem is that I can't find out how to do this.

(How to place the cursor in the right cell and set it in edit mode is the most important problem that I have not find out how to do and how to add the TArticle to the data pointer and how to access it)

Can someone help me out? I will give you more points if you need.

LVL 1
puckoAsked:
Who is Participating?
 
mokuleConnect With a Mentor Commented:
I've tried to do it in the event OnEdited but changing column and entering Edited mode for another column was not possible. So I don't know of such a possibity.
0
 
mokuleCommented:

  vsTree.TreeOptions.MiscOptions :=
    vsTree.TreeOptions.MiscOptions + [toEditable]; // allows edition

  vsTree.TreeOptions.SelectionOptions :=
    vsTree.TreeOptions.SelectionOptions + [toExtendedFocus]; // allows place cursor in the right cell
0
 
puckoAuthor Commented:
It seems like I don't understand here.

Does this show me how to get the first top left cell and set the cell to edit mode so I get the edit box?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
puckoAuthor Commented:
So it is just to add this on form show?
0
 
mokuleCommented:
Not so fast
Previous allows you manual edition and selection

var
  pvn: PVirtualNode;
begin
  pvn := vsTree.GetFirst;        // first row
  pvn := vsTree.GetNext(pvn); // secon row
  vsTree.EditNode(pvn,4);       // edition of 4 column in 2nd row

Be patient. I'm on a trail.

0
 
mokuleCommented:
Sorry, not answered
These options You should set in a Form creation.
0
 
puckoAuthor Commented:
I get an access violation in:


procedure TControl.Show;
begin
  if Parent <> nil then Parent.ShowControl(Self);
  if not (csDesigning in ComponentState) or
    (csNoDesignVisible in ControlStyle) then Visible := True;
end;


when I try this
0
 
puckoAuthor Commented:
Forget my last comment.

Any idea how to get the cell to the text you type in the EditBox and how to add an object in the data pointer?
0
 
mokuleCommented:
type
  PMyRec = ^TMyRec;
  TMyRec = record
    Caption: WideString;
  end;


procedure TMainForm.FormCreate(Sender: TObject);

begin
  // Let the tree know how much data space we need.
  vsTree.NodeDataSize := SizeOf(TMyRec);
  // Set an initial number of nodes.
  vsTree.RootNodeCount := 20;
end;
0
 
mokuleCommented:
//it should work

procedure TMainForm.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
  var Text: WideString);

var
  Data: PMyRec;

begin
  // A handler for the OnGetText event is always needed as it provides the tree with the string data to display.
  // Note that we are always using WideString.
  Data := Sender.GetNodeData(Node);
  if Assigned(Data) then
    Text := Data.Caption;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.VSTFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);

var
  Data: PMyRec;

begin
  Data := Sender.GetNodeData(Node);
  // Explicitely free the string, the VCL cannot know that there is one but needs to free
  // it nonetheless. For more fields in such a record which must be freed use Finalize(Data^) instead touching
  // every member individually.
  if Assigned(Data) then
    Data.Caption := '';
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.VSTInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode;
  var InitialStates: TVirtualNodeInitStates);

var
  Data: PMyRec;

begin
  with Sender do
  begin
    Data := GetNodeData(Node);
    // Construct a node caption. This event is triggered once for each node but
    // appears asynchronously, which means when the node is displayed not when it is added.
    Data.Caption := Format('Level %d, Index %d', [GetNodeLevel(Node), Node.Index]);
  end;
end;
0
 
puckoAuthor Commented:
This is how far I have come. But Nothing is working the way I want. The text don't get edited. And it don't move from cell 1 to cell 3 when I hit enter.



unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, VirtualTrees;

type
  TForm1 = class(TForm)
    VST5: TVirtualStringTree;
    Button1: TButton;
    procedure FormShow(Sender: TObject);
    procedure VST5Edited(Sender: TBaseVirtualTree; Node: PVirtualNode;
      Column: TColumnIndex);
    procedure FormCreate(Sender: TObject);
    procedure VST5GetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
      Column: TColumnIndex; TextType: TVSTTextType;
      var CellText: WideString);
    procedure VST5FreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
    procedure VST5InitNode(Sender: TBaseVirtualTree; ParentNode,
      Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
  private
    { Private declarations }

  public
    { Public declarations }
  end;
type
  PMyRec = ^TMyRec;
  TMyRec = record
    Caption: WideString;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
var
  pvn: PVirtualNode;


begin
  vST5.TreeOptions.MiscOptions:= vsT5.TreeOptions.MiscOptions + [toEditable]; // allows edition
  pvn := vsT5.GetFirst;
  vsT5.EditNode(pvn,1);

end;

procedure TForm1.VST5Edited(Sender: TBaseVirtualTree; Node: PVirtualNode;
  Column: TColumnIndex);
var
  pvn: PVirtualNode;
begin
    if Column = 1  then
    begin
      vsT5.EditNode(Node,3);
    end else
    begin
      VST5.RootNodeCount:= Integer(VST5.RootNodeCount) +1;
      pvn := vsT5.GetNext(Node);
      vsT5.EditNode(pvn,1);
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  vsT5.NodeDataSize := SizeOf(TMyRec);
end;

procedure TForm1.VST5GetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
var
  Data: PMyRec;

begin
  Data := Sender.GetNodeData(Node);
  if Assigned(Data) then
    Text := Data.Caption;


end;

procedure TForm1.VST5FreeNode(Sender: TBaseVirtualTree;
  Node: PVirtualNode);
var
  Data: PMyRec;
begin
  Data := Sender.GetNodeData(Node);
  if Assigned(Data) then
    Data.Caption := '';

end;

procedure TForm1.VST5InitNode(Sender: TBaseVirtualTree; ParentNode,
  Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
var
  Data: PMyRec;
begin
  with Sender do
  begin
    Data := GetNodeData(Node);
    Data.Caption := Format('Level %d, Index %d', [GetNodeLevel(Node), Node.Index]);
  end;

end;

end.
0
 
mokuleCommented:
I've made some mess I think, but

procedure TForm1.vsTreeKeyPress(Sender: TObject; var Key: Char);
var
  pvn: PVirtualNode;
begin
  if key = #13 then
    begin
    pvn := vsTree.GetFirstSelected;
    if pvn <> nil then
      vsTree.EditNode(pvn,2);
    end;
end;

Take You to column 3 to edit mode. If You were in edit mode You must press Enter twice
0
 
mokuleCommented:
In event OnNewText we've got just edited text and Column. It's quite near I think

procedure TForm1.vsTreeNewText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; NewText: WideString);
begin
  Edit1.Text := NewText + ' ' + IntToStr(Column);
end;
0
 
mokuleCommented:
Place TVirtualStringTree with 5 columns and TButton for appending new nodes on a Form.

The program below has all functionality You want.
Still only annoying double texts. Have You got the same effect

const
  COLUMNCOUNT = 5;
type
  PMyRec = ^TMyRec;
  TMyRec = record
    Caption:array[0..COLUMNCOUNT-1] of WideString;  //
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  vsTree.NodeDataSize := SizeOf(TMyRec);

  vsTree.TreeOptions.MiscOptions :=
         vsTree.TreeOptions.MiscOptions + [toEditable];
  vsTree.TreeOptions.SelectionOptions :=
         vsTree.TreeOptions.SelectionOptions + [toExtendedFocus];
end;

procedure TForm1.FormActivate(Sender: TObject);
var
  pvn: PVirtualNode;
begin
  pvn := vsTree.GetFirst;
  vsTree.Selected[pvn] := True;

  if pvn <> nil then
    vsTree.EditNode(pvn,0);
end;

// initializing data in tree view for new node
procedure TForm1.vsTreeInitNode(Sender: TBaseVirtualTree; ParentNode,
  Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
var
  Data: PMyRec;
begin
  with Sender do
  begin
    Data := GetNodeData(Node);

    Data.Caption[0] := Char(Ord('A')+Node.Index);
    Data.Caption[1] := '';
    Data.Caption[2] := '';
    Data.Caption[3] := '';
    Data.Caption[4] := '';

  end;
end;

procedure TForm1.vsTreeGetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
  var CellText: WideString);
var
  Data: PMyRec;
begin
  Data := Sender.GetNodeData(Node);
  if Assigned(Data) then
    begin
    CellText := Data.Caption[Column];
    end;
end;

procedure TForm1.vsTreeKeyPress(Sender: TObject; var Key: Char);
var
  pvn: PVirtualNode;
begin

  if key = #13 then
    begin
    pvn := vsTree.GetFirstSelected;

    if pvn <> nil then
      vsTree.EditNode(pvn,2);
    end;

end;

procedure TForm1.vsTreeNewText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; NewText: WideString);
var
  pvn: PVirtualNode;
  Data: PMyRec;
begin
  Data := vsTree.GetNodeData(Node);
  Data.Caption[Column] := NewText;
  if Column = 0 then
    begin
    Data.Caption[1] := 'x';
    Data.Caption[2] := 'y';
    Data.Caption[3] := 'z';
    Data.Caption[4] := 't';
    end;
end;

// button for appending a new node
procedure TForm1.Button1Click(Sender: TObject);
var
  pvn: PVirtualNode;
begin
  vsTree.RootNodeCount := vsTree.RootNodeCount+1;
  pvn := vsTree.GetLast;
  vsTree.Selected[pvn] := True;

  if pvn <> nil then
    vsTree.EditNode(pvn,0);
end;

0
 
mokuleCommented:
Some minor corrections done and that's it !

const
  COLUMNCOUNT = 5;
type
  PMyRec = ^TMyRec;
  TMyRec = record
    Caption:array[0..COLUMNCOUNT-1] of WideString;  //
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
// at least one node should be
  with vsTree do
    begin
    if RootNodeCount < 1 then
      RootNodeCount := 1;
    Header.Columns[0].Width := 100;
    Header.Columns[1].Width := 200;
    Header.Columns[0].Text := 'Item';
    Header.Columns[1].Text := 'Description';
    Header.Columns[2].Text := 'Qty';
    Header.Columns[3].Text := 'Price';
    Header.Columns[4].Text := 'Value';
    Header.Options := vsTree.Header.Options + [hoVisible];

    NodeDataSize := SizeOf(TMyRec);

    TreeOptions.MiscOptions :=
           TreeOptions.MiscOptions + [toEditable];
    TreeOptions.SelectionOptions :=
           TreeOptions.SelectionOptions + [toExtendedFocus];
    TreeOptions.PaintOptions :=
        TreeOptions.PaintOptions  - [toShowRoot];
    TreeOptions.PaintOptions :=
        TreeOptions.PaintOptions  + [toShowVertGridLines];
    end;
end;

procedure TForm1.FormActivate(Sender: TObject);
var
  pvn: PVirtualNode;
begin
  pvn := vsTree.GetFirst;
  vsTree.Selected[pvn] := True;   // selecting first node

  if pvn <> nil then
    vsTree.EditNode(pvn,0);     // edition of first column
end;

// initializing data in tree view when a new node is added
procedure TForm1.vsTreeInitNode(Sender: TBaseVirtualTree; ParentNode,
  Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
var
  Data: PMyRec;
begin
  with Sender do
  begin
    Data := GetNodeData(Node);
// newly added node will have this data
    Data.Caption[0] := 'Enter item';
    Data.Caption[1] := '';
    Data.Caption[2] := '';
    Data.Caption[3] := '';
    Data.Caption[4] := '';
  end;
end;

procedure TForm1.vsTreeGetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
  var CellText: WideString);
var
  Data: PMyRec;
begin
  Data := Sender.GetNodeData(Node);
  if Assigned(Data) then
    begin
    CellText := Data.Caption[Column];
    end;
end;

procedure TForm1.vsTreeKeyPress(Sender: TObject; var Key: Char);
var
  pvn: PVirtualNode;
begin
  if key = #13 then
    begin
    pvn := vsTree.GetFirstSelected;
    if pvn <> nil then
      vsTree.EditNode(pvn,2);
    end;
end;

procedure TForm1.vsTreeNewText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; NewText: WideString);
var
  pvn: PVirtualNode;
  Data: PMyRec;
begin
  Data := Sender.GetNodeData(Node);
  Data.Caption[Column] := NewText;
  if Column = 0 then // new item
    begin
// here You should do selection from some dataset according
// to NewText and retrieved data place below
    Data.Caption[1] := 'Description';
    Data.Caption[2] := '1';
    Data.Caption[3] := '12.34';
    Data.Caption[4] := '12.34';
    end;
  if Column = 2 then  // new quantity
    begin
    try
      Data.Caption[4] := Format('%.2f',[StrToIntDef(Data.Caption[2],0)*
               StrToFloat(Data.Caption[3])]);
    except
      Data.Caption[4] := '0.00';
      end;
    end;
end;

// button for appending a new node
procedure TForm1.Button1Click(Sender: TObject);
var
  pvn: PVirtualNode;
begin
  vsTree.RootNodeCount := vsTree.RootNodeCount+1;
  pvn := vsTree.GetLast;
  vsTree.Selected[pvn] := True;

  if pvn <> nil then
    vsTree.EditNode(pvn,0);
end;

end.
0
 
puckoAuthor Commented:
I can't test it untill tomorrow. But one thing that I still don't understand is how to add an own defined object on the data pointer.

(Like I can do in a listView:

MyArticle:= TArticle.Create;
MyArticle.Price:= .......


with listview1.items.add do
begin
  Caption:= 'SomeText';
  subItems.Add('some other text');
  data:= MyArticle;
end;

And how to access the Data pointer as an TArticle afterwords.
0
 
mokuleCommented:
// this assignment allows memory allocation each time a new node is added
   vsTree.NodeDataSize := SizeOf(TMyRec);
-----
var
  Data: PMyRec;
begin
  Data := vsTree.GetNodeData(Node);   // retrieves pointer to data associated with a Node
  Data.Caption[Column] := NewText;   // new value assigned to data field
 
0
 
mokuleCommented:
After downloading You should have file VirtualTreeview.chm.
For more details look there for "Data handling"
0
 
puckoAuthor Commented:
Is it possible to se the whole uint you are using and the whole dfm file ? (as text or posted to pucko@linux.nu)

Because I just get an access violation in :

 TCustomVirtualStringTree.DoGetText

When I try to paste in your code and run.
0
 
Lee_NoverCommented:
there's a DB aware version of VTV in the Addons package (same page as the main distro of VTV)
try that .. it worked fine a year ago :-)

2q's 1 answer ? :D
0
 
mokuleCommented:
Here You are.

unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, VirtualTrees;

type
  TForm1 = class(TForm)
    vsTree: TVirtualStringTree;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure vsTreeGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
      Column: TColumnIndex; TextType: TVSTTextType;
      var CellText: WideString);
    procedure vsTreeInitNode(Sender: TBaseVirtualTree; ParentNode,
      Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
    procedure vsTreeKeyPress(Sender: TObject; var Key: Char);
    procedure vsTreeNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
      Column: TColumnIndex; NewText: WideString);
    procedure Button1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

const
  COLUMNCOUNT = 5;
type
  PMyRec = ^TMyRec;
  TMyRec = record
    Caption:array[0..COLUMNCOUNT-1] of WideString;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
// at least one node should be
  with vsTree do
    begin
    if RootNodeCount < 1 then
      RootNodeCount := 1;
    Header.Columns[0].Width := 100;
    Header.Columns[1].Width := 200;
    Header.Columns[0].Text := 'Item';
    Header.Columns[1].Text := 'Description';
    Header.Columns[2].Text := 'Qty';
    Header.Columns[3].Text := 'Price';
    Header.Columns[4].Text := 'Value';
    Header.Options := vsTree.Header.Options + [hoVisible];

    NodeDataSize := SizeOf(TMyRec);

    TreeOptions.MiscOptions :=
           TreeOptions.MiscOptions + [toEditable];
    TreeOptions.SelectionOptions :=
           TreeOptions.SelectionOptions + [toExtendedFocus];
    TreeOptions.PaintOptions :=
        TreeOptions.PaintOptions  - [toShowRoot];
    TreeOptions.PaintOptions :=
        TreeOptions.PaintOptions  + [toShowVertGridLines];
    end;
end;

procedure TForm1.FormActivate(Sender: TObject);
var
  pvn: PVirtualNode;
begin
  pvn := vsTree.GetFirst;
  vsTree.Selected[pvn] := True;   // selecting first node

  if pvn <> nil then
    vsTree.EditNode(pvn,0);     // edition of first column
end;

// initializing data in tree view when a new node is added
procedure TForm1.vsTreeInitNode(Sender: TBaseVirtualTree; ParentNode,
  Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
var
  Data: PMyRec;
begin
  with Sender do
  begin
    Data := GetNodeData(Node);
// newly added node will have this data
    Data.Caption[0] := 'Enter item';
    Data.Caption[1] := '';
    Data.Caption[2] := '';
    Data.Caption[3] := '';
    Data.Caption[4] := '';
  end;
end;

procedure TForm1.vsTreeGetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
  var CellText: WideString);
var
  Data: PMyRec;
begin
  Data := Sender.GetNodeData(Node);
  if Assigned(Data) then
    begin
    CellText := Data.Caption[Column];
    end;
end;

procedure TForm1.vsTreeKeyPress(Sender: TObject; var Key: Char);
var
  pvn: PVirtualNode;
begin
  if key = #13 then
    begin
    pvn := vsTree.GetFirstSelected;
    if pvn <> nil then
      vsTree.EditNode(pvn,2);
    end;
end;

procedure TForm1.vsTreeNewText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; NewText: WideString);
var
  pvn: PVirtualNode;
  Data: PMyRec;
begin
  Data := Sender.GetNodeData(Node);
  Data.Caption[Column] := NewText;
  if Column = 0 then // new item
    begin
// here You should do selection from some dataset according
// to NewText and retrieved data place below
    Data.Caption[1] := 'Description';
    Data.Caption[2] := '1';
    Data.Caption[3] := '12.34';
    Data.Caption[4] := '12.34';
    end;
  if Column = 2 then  // new quantity
    begin
    try
      Data.Caption[4] := Format('%.2f',[StrToIntDef(Data.Caption[2],0)*
               StrToFloat(Data.Caption[3])]);
    except
      Data.Caption[4] := '0.00';
      end;
    end;
end;

// button for appending a new node
procedure TForm1.Button1Click(Sender: TObject);
var
  pvn: PVirtualNode;
begin
  vsTree.RootNodeCount := vsTree.RootNodeCount+1;
  pvn := vsTree.GetLast;
  vsTree.Selected[pvn] := True;

  if pvn <> nil then
    vsTree.EditNode(pvn,0);
end;

end.
//-------------------------------------------------
object Form1: TForm1
  Left = 223
  Top = 110
  Width = 576
  Height = 426
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnActivate = FormActivate
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object vsTree: TVirtualStringTree
    Left = 8
    Top = 8
    Width = 473
    Height = 377
    Header.AutoSizeIndex = 0
    Header.Font.Charset = DEFAULT_CHARSET
    Header.Font.Color = clWindowText
    Header.Font.Height = -11
    Header.Font.Name = 'MS Sans Serif'
    Header.Font.Style = []
    Header.Options = [hoColumnResize, hoDrag]
    ParentBackground = False
    TabOrder = 0
    OnGetText = vsTreeGetText
    OnInitNode = vsTreeInitNode
    OnKeyPress = vsTreeKeyPress
    OnNewText = vsTreeNewText
    Columns = <
      item
        Position = 0
        WideText = 'Column 1'
      end
      item
        Position = 1
        WideText = 'Column 2'
      end
      item
        Position = 2
        WideText = 'Column 3'
      end
      item
        Position = 3
        WideText = 'Column 4'
      end
      item
        Position = 4
        WideText = 'Column 5'
      end>
  end
  object Button1: TButton
    Left = 488
    Top = 8
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 1
    OnClick = Button1Click
  end
end
0
 
puckoAuthor Commented:
Thanks it seems to work well. I will try it a bit more.
I have to find out how to get it to add an new row automaticly after enter the Quantity so I don't have to pusch the button all the time.

One small Question. What do I have to change to make it possible to edit the cell by clicking with the mouse to? as it is now It looks like I have to select the cell and push return button.
0
 
mokuleCommented:
It is possible to edit clicking with mouse.
First click selects cell, second enters edit mode. Try it
0
 
puckoAuthor Commented:
Ok thanks. Then I only have to figure out how to get the new row automaticly
0
 
Lee_NoverCommented:
so you're not considering the VirtualDBTreeView ?
0
 
mokuleCommented:
After changing this procedure the Button can be removed

procedure TForm1.vsTreeKeyPress(Sender: TObject; var Key: Char);
var
  pvn: PVirtualNode;
begin
  if key = #13 then
    begin
    pvn := vsTree.GetFirstSelected;
    if pvn <> nil then
      begin
      if vsTree.FocusedColumn <> 2 then
        begin
        vsTree.FocusedColumn := 2;
        vsTree.EditNode(pvn,2);
        end
      else
        begin
        vsTree.RootNodeCount := vsTree.RootNodeCount+1;
        pvn := vsTree.GetLast;
        vsTree.Selected[pvn] := True;

        if pvn <> nil then
          begin
          vsTree.FocusedColumn := 0;
          vsTree.EditNode(pvn,0);
          end;
        end;
      end;
    end;
end;
0
 
puckoAuthor Commented:
Thanks. One small Question. As it is now I have to push enter twice. (once when when I have entered the value and then I have to hit enter once more to move to the next column. Is there anyway to do it so I only have to push it once?
0
 
puckoAuthor Commented:
My liast little problem that I have problem finding out how to do is that thing with an Object on the data pointer.

I change the definition in the top of your code to:

type
  PMyRec = ^TMyRec;
  TMyRec = class(TObject)
    Caption:array[0..COLUMNCOUNT-1] of WideString;
    Container : TList;
  end;


and get a lot's of access violation.


What more do I have to do?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.