Stupid ComboBox event problem

P

paul.lundin1

Hi,

I cannot figure out why no ComboBox events are firing in my project.
I'm very new to .NET CF programming, so I might be missing something
obvious.

The event handler for "SelectedIndexChanged" gets fired when I first
set the DataSource of the ComboBox, but when I click on the ComboBox
in the emulator, no event handlers get called. Out of desparation,
I've added handlers to SelectedIndexChanged, KeyPress, KeyDown,
LostFocus, and MouseDown, but none of the handler fire.

Any suggestions would be greatly appreciated
 
S

Simon Hart [MVP]

SelectedIndexChanged should work either programmatically or via the UI. Have
you tried using SelectedValueChanged instead, I tend to use this event where
required.
 
P

paul.lundin1

Thanks for the reply.

I have tried both events. This is very frustrating because I must be
missing something obvious. On both the Windows Mobile 5 emulator and
a Windows Mobile 5 device the events fire when the ComboBox is
initialized, but not when it is changed through the UI.

Here's the code:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

this.comboBox1.DataSource = new String[]{"one", "two",
"three"};
}

private void valueChanged(object sender, EventArgs e)
{
MessageBox.Show("valueChanged");
}

private void indexChanged(object sender, EventArgs e)
{
MessageBox.Show("indexChanged");
}
}

Thanks again.
 
G

Guest

I don't see the events being wired up. Are you sure they are in the
designer code? The event handler method names you have are not the ones
typically auto-generated by the designer. You can always add them
explicitly and see if it works.
 
P

paul.lundin1

Sorry, that was just an oversight in my post. The events are wired up
in InitializeComponent. I changed the names from those generated by
the designer because I've tried so many different things to get the
events to fire in the emulator.

//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(26,
26);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(115, 18);
this.comboBox1.TabIndex = 0;
this.comboBox1.DataSource = new System.String[] { "one",
"two", "three" };
this.comboBox1.SelectedIndexChanged += new
System.EventHandler(this.indexChanged);
this.comboBox1.SelectedValueChanged += new
System.EventHandler(this.valueChanged);

Tim
 
S

stealthrabbi

Thanks for the reply.

I have tried both events. This is very frustrating because I must be
missing something obvious. On both the Windows Mobile 5 emulator and
a Windows Mobile 5 device the events fire when the ComboBox is
initialized, but not when it is changed through the UI.

Here's the code:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

this.comboBox1.DataSource = new String[]{"one", "two",
"three"};
}

private void valueChanged(object sender, EventArgs e)
{
MessageBox.Show("valueChanged");
}

private void indexChanged(object sender, EventArgs e)
{
MessageBox.Show("indexChanged");
}
}

Thanks again.

Try changing your event handlers to not be 'private'. don't include an
visibility attribute. just void indesxChanged(...)
 

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