treeView keydown

treeView keydown

Post by Hrvoje Vod » Fri, 25 Mar 2005 00:00:22


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
 
 
 

treeView keydown

Post by Nicholas P » Fri, 25 Mar 2005 00:17:40

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]
- XXXX@XXXXX.COM

 
 
 

treeView keydown

Post by Ludovic SO » Fri, 25 Mar 2005 17:24:29

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 me
tree=new System.Windows.Form.TreeView();
par
tree=new TreeView2();


Hope it helps,

Ludovic Soeur.

"Hrvoje Voda" < XXXX@XXXXX.COM > a rit dans le message de
 
 
 

treeView keydown

Post by Hrvoje Vod » Fri, 25 Mar 2005 17:50:20

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
 
 
 

treeView keydown

Post by Ludovic SO » Fri, 25 Mar 2005 19:06:48

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" < XXXX@XXXXX.COM > a rit dans le message de
 
 
 

treeView keydown

Post by Hrvoje Vod » Fri, 25 Mar 2005 20:37:53

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" < XXXX@XXXXX.COM > wrote in message
news:% XXXX@XXXXX.COM ...


 
 
 

treeView keydown

Post by Ludovic SO » Fri, 25 Mar 2005 21:51:00

how me your code...

"Hrvoje Voda" < XXXX@XXXXX.COM > a rit dans le message de
news:d1u8ti$cno$ XXXX@XXXXX.COM ...
other


 
 
 

treeView keydown

Post by Hrvoje Vod » Sat, 26 Mar 2005 17:14:16

n 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" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...


 
 
 

treeView keydown

Post by Ludovic SO » Sat, 26 Mar 2005 17:31:29

his 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" < XXXX@XXXXX.COM > a rit dans le message de
news:d20hbk$pra$ XXXX@XXXXX.COM ...
System.Windows.Forms.KeyEventArgs
put
The
in