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,
>
[quoted text clipped - 5 lines]
>
> *** Sent via Developersdexhttp://www.developersdex.com***
> Hi there!
>
[quoted text clipped - 14 lines]
>
> *** Sent via Developersdexhttp://www.developersdex.com***