积极答复者
datagrid with checkbox template when scrolling

问题
-
my xaml:
<sdk:DataGrid AutoGenerateColumns="False" IsReadOnly="True" Margin="20,0,20,5" Name="dgFirstView" FrozenColumnCount="1" Height="140" >
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Content="Choose" Tag="{Binding ID}" Height="16" Name="chkChoose" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn><sdk:DataGridTextColumn Binding="{Binding StatusName}" Header="Status" Visibility="Visible" Width="Auto"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>I use checkbox by DataTemplate for select/unselect records.
I have about 10 results in datagrid.itemssource,datagrid auto generates a vertical scroll,then i check two or three records ,but when i scroll mouse,the checkboxs i checked fix other records now.what's the matter? is it a bug?
i searched in the forum about the problem but i can't find the anwser!
i think it causes loadingRow event,but what it does?
anyone can help?thanks
答案
全部回复
-
In DataGrid, DataGridRow is virtualized. When a row is scrolled out of screen, it will be re-used for the item that is just scrolled in from the other side. That's why if you check it and don't change it, it will be scroll in from the other side.
You should try to Bind it to some property in your item, so that it will be refreshed when scrolled in and always stick with your item. Otherwise, you would actually lose users' selection once the row is scrolled out.
-
In DataGrid, DataGridRow is virtualized. When a row is scrolled out of screen, it will be re-used for the item that is just scrolled in from the other side. That's why if you check it and don't change it, it will be scroll in from the other side.
You should try to Bind it to some property in your item, so that it will be refreshed when scrolled in and always stick with your item. Otherwise, you would actually lose users' selection once the row is scrolled out.
试了下,isCheked属性要绑定一个整形的字段,twoway方式。checkbox我是用来选择用,如果不和字段绑定就没有办法吗?
那我的数据库每个表里岂不是要单独加一个字段用来和checkbox绑定?