Article

From:
To:
Elizabeth Krivonos
Subject:
Re: TElXTree in virtual mode and grid-like editing
Newsgroup:
lmd.public.vcl.elpack

Re: TElXTree in virtual mode and grid-like editing

Hi,


Elizabeth Krivonos schrieb:
> "Guido Bruchmann" wrote:
>> What i like to implement is following editing behaviour in an virtual 
>> TElXTree acting as a grid:
>>
>> 1. Keyboard control
>> The user moves the focus by using arrow keys. If he likes to change the 
>> cell content he just starts typing and the cell enters editmode (the 
>> inplaceeditor becomes visible). Hitting the return key applies the 
>> changes, hitting Escape revokes the changes.
> 
> I think that you  can use tree's OnKeyDown event.
> ex:
> 
> procedure TForm1.TreeKeyDown(Sender: TObject; var Key: Word;
>   Shift: TShiftState);
> begin
>   if (key in [ord('A')..Ord('Z'), ord('a')..Ord('z')]) and 
> Assigned(Tree.Selected) then
>   begin
>     Tree.EditItem(Tree.Selected, Tree.SelectColumn); // start edit selected 
> cell
>     ElTreeInplaceEdit1.Editor.Text := chr(Key); // replace editor's value by 
> pressed key
>     ElTreeInplaceEdit1.Editor.CaretX := 1; // change cursor position
>   end;
> end;
> 

Does this example works on a chinese or japanese windows, too? 
ElTreeInplaceEdit1.Editor.Text := chr(Key);

By the way, how do you get SelectColumn to reflect another value than -1, since now i allways used GridTree.ItemFocused.Cells.Col?

What i came to was the following, do you think that it can lead into problems?
procedure TdlgCustomMasterDetailEditorForm.GridTreeKeyDown(Sender: TObject;    var Key: Word; Shift: TShiftState); begin    if not GridTree.IsEditing then    begin      case Key of        // navigational keys are not interesting here        VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN, VK_ESCAPE, VK_NEXT, VK_PRIOR: ;      else        // but all other keys should set the Tree into EditMode        GridTree.EditItem(GridTree.ItemFocused, GridTree.ItemFocused.Cells.Col);        // since the pressed key was not reflected by the inplaceedit we have to        // post it again to the inplace editor        // (...Editor.Handle is FInpEdit of TElTreeView)        if Key = VK_RETURN then ; //DoNothing, Tree handles this        else   PostMessage(TElTreeInplaceEditorHack(TElXTreeHack(GridTree).Editor).Editor.Handle, WM_KEYDOWN, Key, 0);      end;    end; end;

> Please also look at Tree.ExplorerEditMode property. It described in our 
> help, so I not comment this.

I set ExplorerEditMode to true, but if i press the tab-key or pick an 
other cell with the mouse only edit-boxes reflect the changes the user 
made, combos keep the initial values. The same behaviour i see with 
ExplorerEditMode false. For InplaceEditBoxes i can't see any differences.

> 
>> Nice would be the following special behaviour for an InplaceComboBox:
>> If the inplaceeditor is a TElInplaceComboBox entering the editmode should 
>> be possible by pressing the return key or any other key which was the 
>> first character of an item.
> 
> You can use the same event and make conditions for all columns (check 
> Tree.SelectColumn)
> Also look at Tree.Header.Sections[*].FieldType ('Column contents type' in 
> sections editor). ElXTree uses the proper inplace editor using this field's 
> value.
> 
>> 2. Mouse control
>> The next thing is, that if the user takes the mouse for dropping down a 
>> TElInplaceComboBox (in the same grid as described above) and picks a value 
>> he always has to press the return key to apply a selected value. Which 
>> event should be used to catch the change without having to hit the return 
>> key? (the most appropiate i found was the OnClick event of the 
>> InplaceComboBox's editor. Now i only have to pick the value and press the 
>> mouse button in the InplacecomboBox again to apply the selection. But, the 
>> thing that suits me most was that when the user picks an entry it 
>> automatically becomes applied and the inplaceeditor exits edit mode.
>>
> 
> Any tree's inplace editor has Editor property that gain direct access to 
> editor control. In your situation you can handle, for example, editors 
> OnCloseUp event by this way:
> 
>   TForm1 = class(TForm)
> ....
>   private
>     procedure MyCloseUp(Sender: Tobject);
> ....
> implementation
> 
> procedure TForm1.FormCreate(Sender: TObject);
> begin
>   ElTreeInplaceComboBox1.Editor.OnCloseUp := MyCloseUp;
> end;
> 
> procedure TForm1.MyCloseUp(Sender: Tobject);
> begin
>   if (ElTreeInplaceComboBox1.Editor.ItemIndex >=0) then
>     ElXTree1.EndEdit(False); //accept value
> end;
> 

That works fine for me, thanks! I just had to ensure that the tree is 
not in editmode before calling EndEdit (otherwise EndEdit will be called 
twice if you are working with keyboard instead of mouse)

kind regarts   guido
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Fri, 17 May 2024 15:30:46 UTC
Copyright © 2009-2024
HREF Tools Corp.