开发者

Can't Access Checkbox in Datagrid WPF C#

It's my xaml:

<Custom:DataGridTemplateColumn Header="Pilih" Width="50" IsReadOnly="False">
                    <Custom:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox Height="23" Name="ckPilih" Checked="ckPilih_Checked">
                            </CheckBox>
                        </DataTemplate>
        开发者_高级运维            </Custom:DataGridTemplateColumn.CellTemplate>
                </Custom:DataGridTemplateColumn>

when i want to use it(ckPilih) in .cs it can't access


You won't have direct access to this checkbox in code behind because the scope of ckPilih is only inside the DataTemplate

On the side note, I am not sure about your use case but it is not usually recommended to access the checkbox or any other control inside DataTemplate in this manner. You should always try to bind the DataGrid with your datasource. DataGrid will then automatically reflect the changes in DataSource


It is DataTemplate element. you can access it only in your DataTemplate definition. Instead of this, you should use DataGrid.Rows[i].Cell[j].Children property to access collection of controls in a cell.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜