Programatically Select a combobox item using the SelectedValue WPF -


i have combo box loaded through datasource(datatable). on scenario want combo box load desired value passing combobox1.selectedvalue = custid (say it's customer details). custid set selectedvaluepath in xaml. when set that, getting null exception. missing?

my xaml:

<combobox height="23" horizontalalignment="left" margin="332,42,0,0" name="cmbcustomername" verticalalignment="top" width="240" iseditable="true" displaymemberpath="customername" selectedvaluepath="custid" itemspanel="{staticresource cust}" selectionchanged="cmbcustomername_selectionchanged" allowdrop="true" fontweight="normal" text="--select customer name--" issynchronizedwithcurrentitem="true" /> 

update:

c# code:

public customer(int custid) {    initializecomponent();    cmbcustomer.selectedvalue= custid.tostring(); }  private void cmbcustomername_selectionchanged(object sender, selectionchangedeventargs e)     {       cmbcustid.selectedvalue= cmbcustomer.selectedvalue;     } 

the selectedvalue not work in scenario,you should use selecteditem instead,for example:

combobox1.selecteditem = "custid";

or

combobox1.text = "custid";

or

combobox1.selectedindex = combobox1.items.indexof("custid");

or

combobox1.selectedindex = combobox1.findstringexact("custid")


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -