Combo Box Selection Changed Event fires before Selection Changes when using Selected Value (C# WPF) -


i have combo box , button. when click button, it's supposed change selected value , fire code when item changed. unfortunately, selection changed event fires before set selected value of combo box.

my combo box's code on initialize:

listcb.selectedvaluepath = "key"; listcb.displaymemberpath = "value"; listcb.items.add(new keyvaluepair<int, string>(1, "one"));  listcb.selectedvaluepath = "key"; listcb.displaymemberpath = "value"; listcb.items.add(new keyvaluepair<int, string>(2, "two"));  listcb.selectedvaluepath = "key"; listcb.displaymemberpath = "value"; listcb.items.add(new keyvaluepair<int, string>(3, "three")); 

my button's code:

listcb.selectedvalue = 3; 

my selection changed event:

private void listcb_change(object sender, selectionchangedeventargs e) {     messagebox.show("value now: " + listcb.selectedvalue); } 

what happens if example select 1 combo box , click button, value is: 1 instead of three.

am using wrong event? or using wrong way change selected value?

use selectionchangedeventargs newly selected item

private void listcb_change(object sender, selectionchangedeventargs e) {     var item = (keyvaluepair<int, string>)e.addeditems[0];     messagebox.show("value now: " + item.key); } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -