Peter Kiers
asked on
Make sure a folder-node is selected in the treeview.
Dear Experts,
I have an application with a Treeview on it and 2 buttons.
One button is for making a File-node in the treeview and
the other is for making a Folder-node in the treeview.
I have put the code of the 2 buttons in the code-section.
These procedures works perfect, but I want to add a
"ShowMessage('Select a folder first');" to make sure
for the two procedures that a folder-node is selected.
Because:
1. You can only make a folder-node in a folder-node
2. A file-node can only be made in a folder-node
Who can help me with this?
Greetings, Peter Kiers
I have an application with a Treeview on it and 2 buttons.
One button is for making a File-node in the treeview and
the other is for making a Folder-node in the treeview.
I have put the code of the 2 buttons in the code-section.
These procedures works perfect, but I want to add a
"ShowMessage('Select a folder first');" to make sure
for the two procedures that a folder-node is selected.
Because:
1. You can only make a folder-node in a folder-node
2. A file-node can only be made in a folder-node
Who can help me with this?
Greetings, Peter Kiers
procedure TForm1.FileBtnClick(Sender: TObject);
begin
if (TreeView1.Selected <> nil) and
(TreeView1.Selected.ImageIndex = 15) and
(NewItemFrm.ShowModal = mrOk ) then
AddItem(NewItemFrm.Edit1.Text ,17,TreeView1.Selected);
end;
procedure TForm1.FolderBtnClick(Sender: TObject);
begin
if (TreeView1.Selected <> nil) and
(TreeView1.Selected.ImageIndex = 15) and
(NewFolderFrm.ShowModal = mrOk ) then
AddItem(NewFolderFrm.Edit2.Text ,15,TreeView1.Selected);
end;
The NewFolderFrm:
procedure TNewFolderFrm.FormShow(Sender: TObject);
begin
Edit2.Text := '';
ActiveControl := Edit2;
end;
(*---------------------------------------------------*)
procedure TNewFolderFrm.OKBtn2Click(Sender: TObject);
begin
if Edit2.Text <> '' then
ModalResult := mrOk
else
begin
ModalResult := mrNone;
ActiveControl := Edit2;
MessageBox(0, 'You must enter a folder name.', 'Error', MB_OK + MB_ICONEXCLAMATION);
end;
end;
(*---------------------------------------------------*)
The NewItemFrm:
procedure TNewItemFrm.FormShow(Sender: TObject);
begin
Edit1.Text := '';
ActiveControl := Edit1;
end;
(*---------------------------------------------------*)
procedure TNewItemFrm.OKBtn1Click(Sender: TObject);
begin
if Edit1.Text <> '' then
ModalResult := mrOk
else
begin
ModalResult := mrNone;
ActiveControl := Edit1;
MessageBox(0, 'You must enter an item name.', 'Error', MB_OK + MB_ICONEXCLAMATION);
end;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Geert your the best.
i'm trying to follow why you go this way.
a static form hmm
experts mostly give a start for your code, but this doesn't mean the end of the code
if you are a professional programmer, i would strongly advise to look at developmentguru's code
and the benefits they will have in the long term
it is a way of building a library for the many applications you may need to write in the future
a static form hmm
experts mostly give a start for your code, but this doesn't mean the end of the code
if you are a professional programmer, i would strongly advise to look at developmentguru's code
and the benefits they will have in the long term
it is a way of building a library for the many applications you may need to write in the future
ASKER
instead of an Input Query. The reason is hard to explain and a long story.
I thank you for your solution.
500p's comming your way...
Grtz, Peter Kiers