Keyup event firing when it shouldn't!

G

Guest

Hi all,

I'm creating a MDI program, so far when it runs, it shows a dialog box for
logging in (modal dialog form with acceptbutton/cancelbutton set, accept
button validates username and password). After receiving the DialogResult if
all is OK I make a treeview visible (that is docked to left) and load the
navigation options into it. The treeview has a method set for on key up so
that if the key pressed is the enter key, it opens the relavent child form.

Hopefully your with me so far... my problem is that when I press enter to
login from the 'Login' dialogbox the treeview is executing the on keyup event
from the same keypress and showing the first child form option on the
treeview (whatever that maybe- different depending on user). How can I stop
this?

Code is a little like this (wont put it all take too long):

onMDIMainFormLoad(object sender........
{
if (LogonForm.ShowDialog(this)== DialogResult.OK)
{
//Only returns ok if login successfull
LoadNavigationOptionsIntoTreeView();
treeView1.Visible= true;
}
}

treeView1_KeyUp(obj........
{
if (e.KeyCode== Keys.Enter)
{
OpenChildForm(treeView1.SelectedNode);
}
}

Thanks
Gav
 
M

Mr. Arnold

Gav said:
Hi all,

I'm creating a MDI program, so far when it runs, it shows a dialog box for
logging in (modal dialog form with acceptbutton/cancelbutton set, accept
button validates username and password). After receiving the DialogResult
if
all is OK I make a treeview visible (that is docked to left) and load the
navigation options into it. The treeview has a method set for on key up so
that if the key pressed is the enter key, it opens the relavent child
form.

Hopefully your with me so far... my problem is that when I press enter to
login from the 'Login' dialogbox the treeview is executing the on keyup
event
from the same keypress and showing the first child form option on the
treeview (whatever that maybe- different depending on user). How can I
stop
this?

Code is a little like this (wont put it all take too long):

onMDIMainFormLoad(object sender........
{
if (LogonForm.ShowDialog(this)== DialogResult.OK)
{
//Only returns ok if login successfull
LoadNavigationOptionsIntoTreeView();
treeView1.Visible= true;
}
}

treeView1_KeyUp(obj........
{
if (e.KeyCode== Keys.Enter)
{
OpenChildForm(treeView1.SelectedNode);
}
}


I think you should be able to set some kind of global bool flag like bLogin.
You know when you logging in and using that Enter-key. You should know when
to set bLogin to true and false at some point in your program.

treeView1_KeyUp(obj........
{
if (e.KeyCode== Keys.Enter && !bLogin)
{
OpenChildForm(treeView1.SelectedNode);
}
}

Why does it need to be anymore complicated than that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top