Solved

Help with an application that use VirtualTreeView

Posted on 2004-04-01
28
629 Views
Last Modified: 2010-04-05
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.

0
Comment
Question by:pucko
  • 15
  • 11
  • 2
28 Comments
 
LVL 17

Expert Comment

by:mokule
Comment Utility

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

  vsTree.TreeOptions.SelectionOptions :=
    vsTree.TreeOptions.SelectionOptions + [toExtendedFocus]; // allows place cursor in the right cell
0
 
LVL 1

Author Comment

by:pucko
Comment Utility
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
 
LVL 1

Author Comment

by:pucko
Comment Utility
So it is just to add this on form show?
0
 
LVL 17

Expert Comment

by:mokule
Comment Utility
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
 
LVL 17

Expert Comment

by:mokule
Comment Utility
Sorry, not answered
These options You should set in a Form creation.
0
 
LVL 1

Author Comment

by:pucko
Comment Utility
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
 
LVL 1

Author Comment

by:pucko
Comment Utility
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
 
LVL 17

Expert Comment

by:mokule
Comment Utility
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
 
LVL 17

Expert Comment

by:mokule
Comment Utility
//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
 
LVL 1

Author Comment

by:pucko
Comment Utility
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
 
LVL 17

Expert Comment

by:mokule
Comment Utility
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
 
LVL 17

Expert Comment

by:mokule
Comment Utility
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
 
LVL 17

Expert Comment

by:mokule
Comment Utility
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
 
LVL 17

Expert Comment

by:mokule
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:pucko
Comment Utility
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
 
LVL 17

Expert Comment

by:mokule
Comment Utility
// 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
 
LVL 17

Expert Comment

by:mokule
Comment Utility
After downloading You should have file VirtualTreeview.chm.
For more details look there for "Data handling"
0
 
LVL 1

Author Comment

by:pucko
Comment Utility
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
 
LVL 12

Expert Comment

by:Lee_Nover
Comment Utility
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
 
LVL 17

Expert Comment

by:mokule
Comment Utility
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
 
LVL 1

Author Comment

by:pucko
Comment Utility
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
 
LVL 17

Expert Comment

by:mokule
Comment Utility
It is possible to edit clicking with mouse.
First click selects cell, second enters edit mode. Try it
0
 
LVL 1

Author Comment

by:pucko
Comment Utility
Ok thanks. Then I only have to figure out how to get the new row automaticly
0
 
LVL 12

Expert Comment

by:Lee_Nover
Comment Utility
so you're not considering the VirtualDBTreeView ?
0
 
LVL 17

Expert Comment

by:mokule
Comment Utility
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
 
LVL 1

Author Comment

by:pucko
Comment Utility
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
 
LVL 17

Accepted Solution

by:
mokule earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:pucko
Comment Utility
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 40
code issue 8 84
Correct Component for Shopping Cart. 2 84
how can i search if string exist in array ? 3 26
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now