Cheking of entered symbols in current Treenode

  • Thread starter Thread starter Dmitriy Sonechko
  • Start date Start date
D

Dmitriy Sonechko

Hi there!

In my Treeview Control I am trying to edit some of the nodes.
For this purpose I am using mytree.beginedit(), so after this the node
is ready for editing. But I need to avoid of entering some symbols
during editing.
So I need smth like KeyPress Event for current TreeNode to be fired to
implement some symbol cheking.

Could you advice me smth?

Treeview property LabelEdit is set to True.

Thanks in advance!

Dmitriy.
 
The TreeNode itself has no events, so you need to evaluate the
validity after they submit the name. You can do that in the
AfterLabelEdit event of the TreeView. Otherwise, you'll need to
insert yourself into the Windows Event loop. The form's KeyPreview
property won't even cause keypresses to fire the form's KeyPress
event.

Here's code that I tested as working using the AfterLabelEdit.

// Put your valid characters in this string...
private string ValidChars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345679";

private void treeView1_AfterLabelEdit(object sender,
NodeLabelEditEventArgs e)
{
string InvalidChars = "";
for(int x = 0; x < e.Label.Length; x++)
if (!ValidChars.Contains("" + e.Label[x]))
InvalidChars+= e.Label[x];

if (InvalidChars.Length > 0)
{
e.CancelEdit = true;
MessageBox.Show("The following characters are invalid
\n" + InvalidChars);
}
}

HiCSharpner,

smth means something

Thanks,

Dmitriy

*** Sent via Developersdexhttp://www.developersdex.com***

Hi there!

In my Treeview Control I am trying to edit some of the nodes.
For this purpose I am using mytree.beginedit(), so after this the node
is ready for editing. But I need to avoid of entering some symbols
during editing.
So I need smth[something] like KeyPress Event for current TreeNode to be fired to
implement some symbol cheking.

Could you advice me smth[something]?

Treeview property LabelEdit is set to True.

Thanks in advance!

Dmitriy.

*** Sent via Developersdexhttp://www.developersdex.com***
 
Back
Top