checkbox - WPF datagrid and Item Container Recycling -


in wpf have dialog window embedded datagrid. purpose of dialog select files upload. i've added column in datagrid allow selection. there complicated relationship between rows -- uploading 1 file may require upload parent file, example. because of that, there handler updates checkboxes (checking/unchecking , setting isenabled off/on)

i seem have run problem "item container recycling" when many rows in datagrid. of definition looks like

       <datagrid name="mygrid"                        ...                       virtualizingpanel.isvirtualizing="true"                       virtualizingpanel.virtualizationmode="standard">             <datagrid.resources>                 <style targettype="datagridcolumnheader"  x:key="datagridheaderstyle" >                 </style>                 <style x:key="singleclickediting"  targettype="{x:type datagridcell}">                     <eventsetter event="previewmouseleftbuttondown" handler="datagridcell_previewmouseleftbuttondown"></eventsetter>                     <eventsetter event="checkbox.checked" handler="onchecked"/>                     <eventsetter event="checkbox.unchecked" handler="onchecked"/>                 </style>                 ... 

when first created datagrid not able access rows of datagrid until set:

 virtualizingpanel.virtualizationmode="standard" 

now on dialog initialization find can access rows of grid , set them ok.

but odd thing later when user clicks on checkbox, checkbox handler method attempts access checkbox other rows set them. again not of rows available , see strange results.

it if following got turned off datagrid. virtualizingpanel.virtualizationmode="standard"

programmatically in cs code dialog don't see able access parameter grid.virtualizingpanel see value is.

i try rows of grid follows:

    private list<datagridrow> getdatagridrows(datagrid grid)     {         var itemssource = grid.itemssource ienumerable;         list<datagridrow> rows = new list<datagridrow>();         if (null == itemssource) return null;         foreach (var item in itemssource)         {             datagridrow row = grid.itemcontainergenerator.containerfromitem(item) datagridrow;             if (row!=null) rows.add(row);         }         return rows;     } 

the problem following returns null:

grid.itemcontainergenerator.containerfromitem(item) 

how can make sure can list of rows?

================================== added: xaml column definition checkbox column follows:

            <datagrid.columns>                 <datagridcheckboxcolumn elementstyle="{staticresource centeredcheckstyle}" minwidth="15"                 cellstyle="{staticresource singleclickediting}"  visibility="{binding exists}"                binding="{binding path=totransfer, mode=twoway, updatesourcetrigger=propertychanged}" isreadonly="false"                 canusersort="false" canuserresize="false" canuserreorder="false">                     <datagridcheckboxcolumn.headertemplate>                         <datatemplate>                             <checkbox checked="checkbox_checked" unchecked="checkbox_checked" loaded="checkbox_loaded"                                        horizontalcontentalignment="center" horizontalalignment="center"                                       isthreestate="false"  margin="8 0 0 0" padding="0 5 0 0"/>                         </datatemplate>                     </datagridcheckboxcolumn.headertemplate>                 </datagridcheckboxcolumn> 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -