The following MDI Form only allows me to type one character in the
TreeNode's edit control unless the child window is focused in a Normal
(or Maximized) WindowState.

After entering one character the child form is appears to receive
focus, ending the edit operation. If there is more than one MDI child,
then the first child receives focus and is brought to front.

How can I fix this?

public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TreeView^ treeView1;
private: System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->treeView1 = (gcnew
System::Windows::Forms::TreeView());
this->SuspendLayout();
//
// treeView1
//
this->treeView1->Dock =
System::Windows::Forms::DockStyle::Left;
this->treeView1->LabelEdit = true;
this->treeView1->Location = System::Drawing::Point(0, 0);
this->treeView1->Name = L"treeView1";
this->treeView1->Size = System::Drawing::Size(200, 471);
this->treeView1->TabIndex = 0;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode =
System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(696, 471);
this->Controls->Add(this->treeView1);
this->IsMdiContainer = true;
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this,
&Form1::Form1_Load);
this->ResumeLayout(false);

}
#pragma endregion

private:
System::Void Form1_Load(System::Object^ sender,
System::EventArgs^ e)
{
Form^ f = gcnew Form();
f->MdiParent = this;
f->Show();
f->WindowState = FormWindowState::Minimized;

TreeNode^ tn = this->treeView1->Nodes->Add("Top1");
tn->Nodes->Add("sub1");
tn->Nodes->Add("sub2");
tn = this->treeView1->Nodes->Add("Top2");
tn->Nodes->Add("sub3");
tn->Nodes->Add("sub4");
tn->Nodes->Add("sub5");
tn = this->treeView1->Nodes->Add("Top3");
tn->Nodes->Add("sub6");
tn->Nodes->Add("sub7");
tn->Nodes->Add("sub8");
this->treeView1->ExpandAll();
}
};

Re: TreeView TreeNode LabelEdit accepts only one character C++ VS2005 by rsd911

rsd911
Tue Jun 13 19:38:43 CDT 2006

The solution is to put the TreeView inside a Panel (or possibly some
other container control) instead of directly into the Form.


rsd911@gmail.com wrote:
> The following MDI Form only allows me to type one character in the
> TreeNode's edit control unless the child window is focused in a Normal
> (or Maximized) WindowState.
>
> After entering one character the child form is appears to receive
> focus, ending the edit operation. If there is more than one MDI child,
> then the first child receives focus and is brought to front.
>
> How can I fix this?
>
> public ref class Form1 : public System::Windows::Forms::Form
> {
> public:
> Form1(void)
> {
> InitializeComponent();
> }
> protected:
> ~Form1()
> {
> if (components)
> {
> delete components;
> }
> }
> private: System::Windows::Forms::TreeView^ treeView1;
> private: System::ComponentModel::Container ^components;
>
> #pragma region Windows Form Designer generated code
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> void InitializeComponent(void)
> {
> this->treeView1 = (gcnew
> System::Windows::Forms::TreeView());
> this->SuspendLayout();
> //
> // treeView1
> //
> this->treeView1->Dock =
> System::Windows::Forms::DockStyle::Left;
> this->treeView1->LabelEdit = true;
> this->treeView1->Location = System::Drawing::Point(0, 0);
> this->treeView1->Name = L"treeView1";
> this->treeView1->Size = System::Drawing::Size(200, 471);
> this->treeView1->TabIndex = 0;
> //
> // Form1
> //
> this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
> this->AutoScaleMode =
> System::Windows::Forms::AutoScaleMode::Font;
> this->ClientSize = System::Drawing::Size(696, 471);
> this->Controls->Add(this->treeView1);
> this->IsMdiContainer = true;
> this->Name = L"Form1";
> this->Text = L"Form1";
> this->Load += gcnew System::EventHandler(this,
> &Form1::Form1_Load);
> this->ResumeLayout(false);
>
> }
> #pragma endregion
>
> private:
> System::Void Form1_Load(System::Object^ sender,
> System::EventArgs^ e)
> {
> Form^ f = gcnew Form();
> f->MdiParent = this;
> f->Show();
> f->WindowState = FormWindowState::Minimized;
>
> TreeNode^ tn = this->treeView1->Nodes->Add("Top1");
> tn->Nodes->Add("sub1");
> tn->Nodes->Add("sub2");
> tn = this->treeView1->Nodes->Add("Top2");
> tn->Nodes->Add("sub3");
> tn->Nodes->Add("sub4");
> tn->Nodes->Add("sub5");
> tn = this->treeView1->Nodes->Add("Top3");
> tn->Nodes->Add("sub6");
> tn->Nodes->Add("sub7");
> tn->Nodes->Add("sub8");
> this->treeView1->ExpandAll();
> }
> };