Topic: 3 doubts !!!

-How can you create a menu for a form other than the main one?
-In the tree view object, how can it be disabled by code that can be created, edited or deleted?
-How could the sort option be disabled in the grid without disabling the grid?

Re: 3 doubts !!!

Hello wenchester 21

1 - How to create menus on another form than Form1 (main form)

procedure Form1_OnShow (Sender: string; Action: string); // event OnShow
var
   MyItem1: TMenuItem;
   MyItem2: TMenuItem;
   MySubItem3: TMenuItem;

   MenuForm2: TMainMenu;
begin


   MyItem1 := TMenuItem.Create (Form2);
   MyItem1.Caption := 'MyItem1';
   MyItem1.OnClick := @MenuClick1;

   MyItem2 := TMenuItem.Create (Form2);
   MyItem2.Caption := 'MyItem2';


   MySubItem3 := TMenuItem.Create (Form2);
   MySubItem3.Caption := 'Submenu';
   MySubItem3.OnClick := @MenuClick3;



   MenuForm2 := TMainMenu.Create(Form2); // Create MainMenu on Form2
   MenuForm2.Items.Add(MyItem1);         // you can use ADD or INSERT
   MenuForm2.Items.Insert(0, MyItem2);   // you can use ADD or INSERT
   MyItem2.Add(MySubItem3);

end;


procedure MenuClick1 (Sender: string);
begin
     ShowMessage('Hello from MyItem1');
end;

procedure MenuClick3 (Sender: string);
begin
     ShowMessage('Hello from Submenu');
end;

begin

end.

JB

Re: 3 doubts !!!

Hi Wen, Salut Jean,
To disable column sorting in the tablegrid, please have a look at the attached example.
Sorting can be disabled for one, some or all of the columns depending on your requirement.
Derek.

Post's attachments

Attachment icon wenchester gridsort.zip 339.62 kb, 231 downloads since 2021-05-17 

Re: 3 doubts !!!

hi jean and derek, thanks for your solutions, they gave me the push to what i am doing.  I would only have question 2, if you have any ideas, tell me. Thanks

Re: 3 doubts !!!

Hi,
To disable adding, editing and deleting treeview items, try it like this (see attached).
Not sure why you would want to do this though.
Derek.

Post's attachments

Attachment icon treeview rightclick.zip 336.6 kb, 251 downloads since 2021-05-17 

Re: 3 doubts !!!

Hello Wenchester21, Hello Derek

For item 2, Derek's solution is the one.
To add something else to a MVD treeview (Derek was faster than me in responding), if ever you want translate caption
of treeview popoup menu in you own language,  :

procedure Form1_OnShow (Sender: TObject; Action: string);
begin
    Form1.TreeView1.dbPopupMenu.Items[0].Caption := 'Ajouter un enfant';    // here, into French
    Form1.TreeView1.dbPopupMenu.Items[1].Caption := 'Ajouter une racine';
    Form1.TreeView1.dbPopupMenu.Items[2].Caption := 'Editer';
    Form1.TreeView1.dbPopupMenu.Items[3].Caption := 'Effacer';
    Form1.TreeView1.dbPopupMenu.Items[5].Caption := 'Rechercher';
end;

JB

Re: 3 doubts !!!

derek wrote:

Hi,
To disable adding, editing and deleting treeview items, try it like this (see attached).
Not sure why you would want to do this though.
Derek.

Hi Derek and Jean
And how do I return the tree to normal?