Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

treeView keydown

0 views
Skip to first unread message

Hrvoje Voda

unread,
Mar 23, 2005, 10:00:22 AM3/23/05
to
What is wrong in this code?

private void tree_KeyDown(object sender, System.Windows.Forms.KeyEventArgs
e)

{

if (e.KeyCode == Keys.Enter )

{

ConnString = "workstation id=HRV;packet size=4096;integrated
security=SSPI;data source=HRV;persist security info=False;initial
catalog=DVD Kolekcija";

bDb = new Db(ConnString);

grid.Refresh();


grid.Table = bDb.datasetDVD.Tables ["DVD"];

}

}

I press ENTER when I'm on treeview control but nothing happens!

Hrcko


Nicholas Paldino [.NET/C# MVP]

unread,
Mar 23, 2005, 10:17:40 AM3/23/05
to
Hrvoje,

I would step through the code, and see if an exception is thrown
anywhere. If an exception is thrown, it will be swallowed by the code
calling your event handler, and do nothing.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"Hrvoje Voda" <hrvoj...@luatech.com> wrote in message
news:d1s0d7$bhv$1...@ls219.htnet.hr...

Ludovic SOEUR

unread,
Mar 24, 2005, 3:24:29 AM3/24/05
to
Nothing is wrong with your code. Enter key is already used for an other
control (for example, if you set an accetButton for your form). The solution
is to says to the control that Enter key is an input key.

To do so, override TreeView class like following :
class TreeView2:TreeView {
protected override bool IsInputKey(Keys keyData) {
if (keyData==Keys.Enter) return true;
return base.IsInputKey (keyData);
}
}

Note that if you want to catch other keys like TAB, you can use a switch
statement. And if you want to catch ALL keys, always return true in
IsInputKey method.

And do not forget to replace
System.Windows.Form.TreeView tree;
par
TreeView2 tree;

et de même
tree=new System.Windows.Form.TreeView();
par
tree=new TreeView2();


Hope it helps,

Ludovic Soeur.

"Hrvoje Voda" <hrvoj...@luatech.com> a écrit dans le message de
news:d1s0d7$bhv$1...@ls219.htnet.hr...

Hrvoje Voda

unread,
Mar 24, 2005, 3:50:20 AM3/24/05
to
I have a problem with overriding, because I'm using my user control.
I created some aditional functions for it, so when I put this code I can't
access my own functions!

Hrcko


"Ludovic SOEUR" <Ludovi...@hotmail.com> wrote in message
news:OvXvktEM...@TK2MSFTNGP10.phx.gbl...

Ludovic SOEUR

unread,
Mar 24, 2005, 5:06:48 AM3/24/05
to
If I have understood, you have already overloaded TreeView, so just put
IsInputKey method in your overloaded control.
If I didn't, show me your code.

Ludovic Soeur.


"Hrvoje Voda" <hrvoj...@luatech.com> a écrit dans le message de

news:d1tv3d$oe2$1...@ss405.t-com.hr...

Hrvoje Voda

unread,
Mar 24, 2005, 6:37:53 AM3/24/05
to
I put IsInputKey method in my user control, but it still doesn't work!
Should I call it somehow in my other application?

Hrcko


"Ludovic SOEUR" <Ludovi...@hotmail.com> wrote in message

news:%236llvmF...@TK2MSFTNGP14.phx.gbl...

Ludovic SOEUR

unread,
Mar 24, 2005, 7:51:00 AM3/24/05
to
Show me your code...

"Hrvoje Voda" <hrvoj...@luatech.com> a écrit dans le message de

news:d1u8ti$cno$1...@ss405.t-com.hr...

Hrvoje Voda

unread,
Mar 25, 2005, 3:14:16 AM3/25/05
to
In my application I have my user control and this code :

in constructor :

treeKolekcija.KeyDown += new KeyEventHandler(tree_KeyDown) ;

private void tree_KeyDown(object sender, System.Windows.Forms.KeyEventArgs
e)
{
if (e.KeyCode == Keys.Enter )
{
ConnString = "workstation id=HRV;packet size=4096;integrated
security=SSPI;data source=HRV;persist security info=False;initial
catalog=DVD Kolekcija";
bDb = new Db(ConnString);
grid.Refresh();
grid.Table = bDb.datasetDVD.Tables ["DVD"];
}
}

I put your code into my user control :

protected override bool IsInputKey(Keys keyData)
{
if (keyData==Keys.Enter) return true;
return base.IsInputKey (keyData);
}

"Ludovic SOEUR" <Ludovi...@hotmail.com> wrote in message
news:Oi5b1CHM...@tk2msftngp13.phx.gbl...

Ludovic SOEUR

unread,
Mar 25, 2005, 3:31:29 AM3/25/05
to
This is how you must change your code :

namespace MonNameSpace {
public class MyUserControl : UserControl {
....
....
TreeView2 treeKolekcija;
....
....
....
private void InitializeComponent() {
...
...
this.treeKolekcija = new TreeView2();
...
...
}
...
...


private void tree_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e) {

...
your code
...
}
...
...


}
class TreeView2:TreeView {
protected override bool IsInputKey(Keys keyData) {
if (keyData==Keys.Enter) return true;
return base.IsInputKey (keyData);
}
}
}

Of course, if you have already overloaded TreeView Class, do not extend
TreeView2 from TreeView but from your own TreeView class.

Hope it helps...
If it does not, I would send you a complete example.

Ludovic Soeur.

"Hrvoje Voda" <hrvoj...@luatech.com> a écrit dans le message de

news:d20hbk$pra$1...@ss405.t-com.hr...

0 new messages