wpf - TwoWay binding a table to a datagrid which has a ComboBox column and bind to another table? -


twoway binding table datagrid has combobox column , bind table?

i have datagrid twoway bind table accounts. whenever update button clicked, i'll update data adapter, updates table. works fine.

now, in table accounts, there column called locationcode. value of locationcode comes table locations. so, when user makes changes locationcode in datagrid, user should able choose locationcode list of values in table locations. means in datagrid, locationcode column should combobox column datacontent table locations.

is there way in datagrid, shows value of table accounts, when user click locations cell, show combobox, user can choose combobox. once value updated, if update data adapter, update table accounts automatically (twoway binding)?

here i'm doing now:

<datagrid autogeneratecolumns="false" name="dgactloc" grid.row="0" isreadonly="false" fontweight="bold" padding="5" margin="5" itemssource="{binding path=., mode=twoway}" selectionmode="single" fontsize="16" rowdetailsvisibilitymode="visiblewhenselected" preparingcellforedit="dgactloc_preparingcellforedit">  <datagrid.columns>      <datagridtextcolumn binding="{binding path=acctlocid, mode=twoway}" header="account location id" isreadonly="true" >          blah, blah      </datagridtextcolumn>      <datagridtextcolumn binding="{binding path=accountid, mode=twoway}" header="account id" />          blah, blah      <datagridcomboboxcolumn header="location code" width="*"  selectedvaluebinding="{binding path=locationcode}" selectedvaluepath="locationcode" displaymemberpath="locationcode" >      </datagridcomboboxcolumn>  </datagrid> 

then in code behind:

private void dgactloc_preparingcellforedit(object sender, datagridpreparingcellforediteventargs e) {     if (e.column.header.equals("location code"))     {         string cmd = "select locationcode location order locationcode";         datatable dt = clsdataaccess.gettablefromdb(cmd);          combobox cboeditingelement = (combobox)(e.editingelement);         bindingoperations.setbinding(cboeditingelement, combobox.itemssourceproperty, new binding() { source = dt });      } } 

however, has problem. when window shows up, column blank should have value (red circle).

enter image description here

if click cell, combobox shows up, , can select value. if click update button, updates value in table.

enter image description here

so, question is: why blank (in first screen shot), how fix it?

thanks


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -