473,396 Members | 1,826 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,396 software developers and data experts.

When is this event ListBox_object.KeyDown occurring

Hello!!

I have a derived class called StringClassEditor which inherit from
UITypeEditor listed below.

Now to my question in method EditValue in this class I have this statement
lb.KeyDown += new KeyEventHandler(ListBox_KeyDown);
I have set a breakpoint in the event handler method ListBox_KeyDown but
this method is never called. So this event KeyDown for control ListBox is
never occuring.
I just wonder when is this event occurring?
Can I simply remove statement lb.KeyDown += new
KeyEventHandler(ListBox_KeyDown);
and the method ListBox_KeyDown.

The other event handling methods which are ListBox_SelectedIndexChanged and
ListBox_SelectedIndexChanged
is called so these work as they should.

I have removed code that is irrelevant for my question.

public class StringClassEditor : UITypeEditor
{
...
...
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
Type type = value.GetType(); //get type for value

if (StringClassHasValueList(value as StringClass)) // make
ArrayList if not exist
{
wse = (IWindowsFormsEditorService )
(provider.GetService(typeof(IWindowsFormsEditorSer vice)));
if (wse != null)
{
ListBox lb = new ListBox();
editedSc = value as StringClass;
originalValue = editedSc.StrValue;
string[] values = (string [])
(editedSc.ValuesList.ToArray(typeof(string)));
lb.Items.AddRange(values);
int selectedIndex = editedSc.StrValue != null ?
lb.Items.IndexOf(editedSc.StrValue) : -1;
if (selectedIndex != -1)
lb.SelectedIndex = selectedIndex;

lb.KeyDown += new
KeyEventHandler(ListBox_KeyDown);
lb.SelectedIndexChanged += new
EventHandler(ListBox_SelectedIndexChanged);
lb.Click += new
EventHandler(ListBox_Click);

wse.DropDownControl(lb);
wse = null;
return editedSc;
}
}
return base.EditValue (context, provider, value);
}

private void ListBox_KeyDown(object sender, KeyEventArgs e)
{
if (wse != null && (e.KeyCode == Keys.Escape || e.KeyCode ==
Keys.Return))
{
if (e.KeyCode == Keys.Escape)
editedSc.StrValue = originalValue;
wse.CloseDropDown();
}
}

private void ListBox_Click(object sender, EventArgs e)
{
wse.CloseDropDown();
}

private void ListBox_SelectedIndexChanged(object sender, EventArgs
e)
{
string test = sender.ToString();
ListBox lb = (ListBox) sender;
editedSc.StrValue = (string)lb.SelectedItem;
}
}

//Many thanks!
//Tony
May 5 '06 #1
0 1737

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: dixie | last post by:
I want to run an event when I press the Ctl key simultaneously with the K key. How do I achieve this in VBA? dixie
2
by: orekinbck | last post by:
Hi There In C# windows app, .NET 2003 I have a text box with the following event handler: private void textBox3_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode...
1
by: Rene | last post by:
Hi, I am running is some problems with the KeyPreview and KeyPress events. The KeyPress event is only triggered when there this an focusable control on the form. When all controls are disabled...
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...
2
by: Phill. W | last post by:
How do I propagate an Event that I've just handled? I have a UserControl containing, among other things, a TextBox. The UserControl handles KeyDown/KeyPress Events for both itself and the...
3
by: Just Me | last post by:
I noticed that I don't get KeyDown nor KetPress events if NumLock is not on. I can probably find a workaround but it would be nice to know what the rules are. Can anyone tell me when KeyPress...
2
by: Phil Galey | last post by:
I have a Panel control docked on all sides on a form and the panel control contains a PictureBox. I'm using the KeyDown event of the form to respond to the and keys for resizing the image and the...
3
tpgames
by: tpgames | last post by:
2x2 Sudoku doesn't work at all. The images don't show up on the grid. I don't understand JavaScript very well. Just learning it. Thanks! <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01...
7
by: Sin Jeong-hun | last post by:
I have a dialog form which pops up from the main window using the ShowDialog() method. this dialog has no or button, and it has quite a lot of controls on it. Now, I want to close this dialog...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.