By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,315 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,315 IT Pros & Developers. It's quick & easy.

treeView keydown

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Hrvoje Voda" <hr*********@luatech.com> wrote in message
news:d1**********@ls219.htnet.hr...
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

Nov 17 '05 #2

P: n/a
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" <hr*********@luatech.com> a écrit dans le message de
news:d1**********@ls219.htnet.hr...
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

Nov 17 '05 #3

P: n/a
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" <Lu***********@hotmail.com> wrote in message
news:Ov**************@TK2MSFTNGP10.phx.gbl...
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" <hr*********@luatech.com> a écrit dans le message de
news:d1**********@ls219.htnet.hr...
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


Nov 17 '05 #4

P: n/a
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" <hr*********@luatech.com> a écrit dans le message de
news:d1**********@ss405.t-com.hr...
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" <Lu***********@hotmail.com> wrote in message
news:Ov**************@TK2MSFTNGP10.phx.gbl...
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" <hr*********@luatech.com> a écrit dans le message de
news:d1**********@ls219.htnet.hr...
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



Nov 17 '05 #5

P: n/a
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" <Lu***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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" <hr*********@luatech.com> a écrit dans le message de
news:d1**********@ss405.t-com.hr...
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" <Lu***********@hotmail.com> wrote in message
news:Ov**************@TK2MSFTNGP10.phx.gbl...
> 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" <hr*********@luatech.com> a écrit dans le message de
> news:d1**********@ls219.htnet.hr...
>> 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
>>
>>
>
>



Nov 17 '05 #6

P: n/a
Show me your code...

"Hrvoje Voda" <hr*********@luatech.com> a écrit dans le message de
news:d1**********@ss405.t-com.hr...
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" <Lu***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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" <hr*********@luatech.com> a écrit dans le message de
news:d1**********@ss405.t-com.hr...
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" <Lu***********@hotmail.com> wrote in message
news:Ov**************@TK2MSFTNGP10.phx.gbl...
> 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" <hr*********@luatech.com> a écrit dans le message de
> news:d1**********@ls219.htnet.hr...
>> 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
>>
>>
>
>



Nov 17 '05 #7

P: n/a
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" <Lu***********@hotmail.com> wrote in message
news:Oi**************@tk2msftngp13.phx.gbl...
Show me your code...

"Hrvoje Voda" <hr*********@luatech.com> a écrit dans le message de
news:d1**********@ss405.t-com.hr...
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" <Lu***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
> 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" <hr*********@luatech.com> a écrit dans le message de
> news:d1**********@ss405.t-com.hr...
>> 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" <Lu***********@hotmail.com> wrote in message
>> news:Ov**************@TK2MSFTNGP10.phx.gbl...
>> > 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" <hr*********@luatech.com> a écrit dans le message de
>> > news:d1**********@ls219.htnet.hr...
>> >> 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
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 17 '05 #8

P: n/a
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" <hr*********@luatech.com> a écrit dans le message de
news:d2**********@ss405.t-com.hr...
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" <Lu***********@hotmail.com> wrote in message
news:Oi**************@tk2msftngp13.phx.gbl...
Show me your code...

"Hrvoje Voda" <hr*********@luatech.com> a écrit dans le message de
news:d1**********@ss405.t-com.hr...
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" <Lu***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
> 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" <hr*********@luatech.com> a écrit dans le message de
> news:d1**********@ss405.t-com.hr...
>> 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" <Lu***********@hotmail.com> wrote in message
>> news:Ov**************@TK2MSFTNGP10.phx.gbl...
>> > 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" <hr*********@luatech.com> a écrit dans le message de
>> > news:d1**********@ls219.htnet.hr...
>> >> 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
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.