473,320 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

treeView keydown

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
8 4372
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: Andrew DeFaria | last post by:
I thought this would be fairly straight forward but apparently it's not. Given the following html file: <!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"> <html> <head>...
7
by: (Pete Cresswell) | last post by:
I've got KeyDown coding and it fires when other keys are pressed, but when Enter is pressed, nothing. I'd like to support the (standard?) Windows behavior of executing DblClick processing when...
3
by: Frank T. Clark | last post by:
How do I redirect or capture keydown events in a parent form from a child form? I have a main form which displays another informational form marked "SizableToolWindow". Form child = new...
3
by: bardo | last post by:
I have a Datagrid that is inside a panel. I want to use the keyDown event to reconize the arrow keys. But I have no luck at all. The problem is that the keydown event won't fire at all, unless I...
4
by: Anne | last post by:
hie again, i have 3 textbox and i would like the user to go to the next textbox by pressing the 'ENTER' key. i have tried using this: Private Sub txtRequestor_KeyDown(ByVal sender As...
3
by: Colin McGuire | last post by:
Hi, can I ask what I should be doing below. For some reason the method KeyDown doesn't exist in MyBase. Thank you Colin Private Sub TextBox1_KeyDown(ByVal sender As Object, _ ByVal e As...
0
by: Peter | last post by:
I have a VB6 program which can receive Keydown events on an ActiveX control. The ActiveX control can't fire keydown events so I put a picturebox below the ActiveX control. I write codes in...
3
by: MLM450 | last post by:
I have a control that handles the KeyDown event but it does not seem to execute when a combination of keys is pressed - like CTRL+Z. If I press CTRL, it executes. If I press Z, it executes. But the...
3
by: AmaraEmerson | last post by:
I've got a treeview with some items, and I want to catch the keydown events to check if the enter key is pressed. I'm doing this with the treeview's keydown event. However, every time enter key is...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.