Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a customized combo box event

Status
Not open for further replies.

robUK2

Programmer
Mar 10, 2008
57
TH
Hello,

I am creating a mobile 5 application using CF 3.5.

I have a combo box that keeps on firing on the selectionIndexChanged event. I need this event to get an item from the combo box. However, when the combo datasource is set it will fire this. I have resolved this issue with a simple bool test. See code below. However, I have noticed that the event often fires. Its hard to track down what is causing this to fire.

Code:
 //Set to false to prevent pre-firing of selectValue changed event before datasource is set.
this.cboDataSourceSet = false;
this.cboRecentNumbers.DataSource = this.bsRedialedNumbers;
this.cboRecentNumbers.DisplayMember = "Name";
this.cboRecentNumbers.ValueMember = "ID";
this.cboDataSourceSet = true;



Code:
private void cboRecentNumbers_SelectedIndexChanged(object sender, EventArgs e)
{
            
     if (this.cboDataSourceSet)
     {
         //Do something here.              
     }
}

I am thinking of 2 methods to solve this issue:
1) Is there a way to stop the event being fired or a way to track down the event to find what other conditions are causing it to fire?

2) Inherit from the combo box class and add your own SelectionChanged Event. (Can anyone point me in the right direction for doing something like this?).

I would perfer method 2 as I have never done anything like that before. So good for learning something new.

Many thanks for any suggestion and help with this,

Steve
 
i have not worked with CF or 3.5, but this doesn't sound like the expected behavior of the control. try building a simple model to reproduce the issue.

1 page with 1 drop down. wire up the binding and selected index changing events and test. if the problem does not occur the issue is with your original code. if the problem occur it's either how your loading/selecting the values, or a bug.


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I've run into similar problems in windows forms.

Does CF have a "SelectionChangeCommitted" event that you can use (I imagine that it would)? You probably should use that, if you only want to capture user initiated changes.

site said:
SelectedIndexChanged
* raised when DataSource is set
* raised when SelectedIndex is set programmatically

SelectionChangeCommitted
* not raised when DataSource is set
* not raised when SelectedIndex is set programmatically

From here:
Hope this helps,

Alex

[small]----signature below----[/small]
Majority rule don't work in mental institutions

My Crummy Web Page
 
Hello,

Thanks for the reply.

The CF 3.5 doesn't have a SelectedChangeCommitted event.

I have worked with the compact framework before. So just looking for a better solution.

I would be interested into how to make a customized selectedChange event.

If anyone has any details on how to do this.

Many thanks,

Steve
 
I'd look at creating a UserControl containing a ComboBox. Then applying the logic you have within the UserControl to determine whether your event is raised to the form or not (in the ComboBox's SelectedINdexChanged event handler).

You could also make your forms implement an interface requiring them to expose a public method, then cast the UserControl's parent to that interface and call the method from within your event handler.

You'll also need to add methods to your UserControl for things like filling the combo's data source, etc...

Hope this gets you started,

ALex

[small]----signature below----[/small]
Majority rule don't work in mental institutions

My Crummy Web Page
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top