data binding - Find a WPF Combobox item using SelectedValue from Binded Combobox -
can me find combobox item using value property. combobox binded dataset. here code.
xaml code
combobox grid.column="0" grid.row="3" height="23" horizontalalignment="left" margin="12,23,0,0" name="cbxdesignation" verticalalignment="top" width="120" itemssource="{binding}" selectedvaluepath="desig_code" selecteditem="desig_name"
c# code behind.
//populate designation <i> strsql = "select desig_code, desig_name desig_master"; dscommon = cdtier.returndataset(strsql); cbxdesignation.datacontext = dscommon.tables[0].defaultview; cbxdesignation.displaymemberpath = dscommon.tables[0].columns["desig_name"].tostring(); cbxdesignation.selectedvaluepath = dscommon.tables[0].columns["desig_code"].tostring(); if (dscommon.tables[0].rows.count > 0) cbxdesignation.selectedindex = 0; dscommon.dispose(); </i>
based on employee selection, want display designation. in database have designation code (desig_code) have mapped in selectedvaluepath.
how can achieve this?
i have cbxdesignation.selectedvalue
below
cbxdesignation.selectedvalue = (dsmaster.tables[0].rows[0] ["desig_code"].tostring() != "") ? dsmaster.tables[0].rows[0] ["desig_code"].tostring() : "0";
please anyone.....
thank you.
try using cbxdesignation.itemcontainergenerator.containerfromitem(cbxdesignation.selectedvalue)
should give comboboxitem
.
alternatively use itemcontainergenerator.containerfromindex(cbxdesignation.selectedindex)
alternative
Comments
Post a Comment