得到的DataGrid复选框的价值? [英] get value of checkbox from datagrid?

查看:74
本文介绍了得到的DataGrid复选框的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<DataGridTemplateColumn Header="IsAdmin">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox Name="IsAdminCheckBox" IsChecked="{Binding Path=IsAdmin}" Click="IsAdmin_Click" CommandParameter="{Binding Path=Id}"/>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

这是我对在我的程序一个DataGrid的代码。在CS文件,在点击事件,我想看看,当他们检查它,把它改为托运,或取消选中,这样我就可以在数据库处理,改变从管理用户而不是管理,反之亦然。然而只是打电话IsAdminCheckBox不起作用,因为它无法找到它,并且还调用datagridName.IsAdminCheckBox不起作用。有谁知道如何访问复选框的状态?

This is the code that I have for a datagrid in my program. In the CS file, in the click event, I want to see if when they check it, it changed to checked, or unchecked, so that I can handle in the database, changing the user from admin to not admin and vise versa. However just calling IsAdminCheckBox doesn't work because it can't find it, and also calling the datagridName.IsAdminCheckBox doesn't work. Does anyone know how to access the status of the checkbox?

推荐答案

您不能访问复选框,这样一来,因为有可能成为他们中的一多,名称是仅对在的DataTemplate

You can't access the checkbox this way, because there may be more than one of them, the name is valid only inside the DataTemplate.

在事件处理中, 发件人参数应该是复选框,你只需要投它,然后你可以访问器isChecked 属性。另一种办法是处理经过 Uncheked 事件。

In the event handler, the sender parameter should be the CheckBox, you just have to cast it and then you can access the IsChecked property. Another option would be to handle the Checked and Uncheked events.

但我认为更好的办法是在绑定的类来处理这个问题,不是你的GUI的代码隐藏,关注点分离和所有。

But I think a better way would be to handle this in the bound class, not in code-behind of your GUI, separation of concerns and all that.

这篇关于得到的DataGrid复选框的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆