c# - WPF ListView Sorting issue with Cell Templated TextBox -


there problem wpf listview. listview bound datatable db. there no mvvm here. everthing in codebehind.

in listview, 3rd column has celltemplate. , column bound tax percentage column in datatable. tax percentage column of type varchar [this based on other business logic hence cannot change datatype].

 <gridviewcolumn.celltemplate>    <datatemplate>       <textbox name="txt1" text="{binding taxpercent, mode=twoway, updatesourcetrigger=propertychanged}"                 previewtextinput="txt1_previewtextinput" width="105">                <textbox.borderbrush>                     <multibinding converter="{staticresource textcomparer}">                          <binding path="taxpercent" mode="twoway" />                          <binding path="taxpercent_val" mode="twoway"/>                     </multibinding>                </textbox.borderbrush>       </textbox>                                            </datatemplate> 

when listview loaded, populates data db. let's 4 rows of data in listview. below shown tax column.

tax percentage -------------- 2 1 4 3 

after this, edited tax percentage , clicked on gridviewheadercolumn sort it. sorts correctly. sorting order desending. below code sorting.

    icollectionview dataview = collectionviewsource.getdefaultview(lvtax.itemssource);         if (dataview != null)         {                           dataview.sortdescriptions.clear();             sortdescription sd = new sortdescription("taxpercent", direction);             dataview.sortdescriptions.add(sd);             dataview.refresh();                        } 

after sorting first time, when edited or changed value in tax percentage text box, after typing first digit, automatically sorts again !!! means edited row goes down or depends on last sorted direction !!!

the above event handler "txt1_previewtextinput" make numeric text box. commented above handler , tried. no use. commented multibinding in xaml, no use.

what problem ???

any idea ??

change updatesourcetrigger lostfocus in textbox binding, triggering property change user starts typing, after triggering on lostfocus grid sorted loses focus.

<textbox name="txt1" text="{binding taxpercent, mode=twoway, updatesourcetrigger=lostfocus}" 

and if need sort clicking header change binding mode oneway like

<textbox name="txt1" text="{binding taxpercent, mode=oneway}" 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -