treeView keydown

H

Hrvoje Voda

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
L

Ludovic SOEUR

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.
 
H

Hrvoje Voda

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 said:
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 said:
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
 
L

Ludovic SOEUR

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 said:
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 said:
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 said:
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
 
H

Hrvoje Voda

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 said:
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 said:
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 said:
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" <[email protected]> a écrit dans le message de
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
 
L

Ludovic SOEUR

Show me your code...

Hrvoje Voda said:
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 said:
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 said:
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


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" <[email protected]> a écrit dans le message de
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
 
H

Hrvoje Voda

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 said:
Show me your code...

Hrvoje Voda said:
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 said:
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" <[email protected]> a écrit dans le message de
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


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" <[email protected]> a écrit dans le message de
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
 
L

Ludovic SOEUR

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 said:
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 said:
Show me your code...

Hrvoje Voda said:
I put IsInputKey method in my user control, but it still doesn't work!
Should I call it somehow in my other application?

Hrcko


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" <[email protected]> a écrit dans le message de
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


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" <[email protected]> a écrit dans le message de
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
 

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