如何使Silverlight Grid仅允许选择一个复选框. [英] How to make Silverlight Grid to allow only one Checkbox to select.
本文介绍了如何使Silverlight Grid仅允许选择一个复选框.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Silverlight网格,其中有一个Checkbox列,当前用户可以选择多行.但是Silverlight网格应该只允许选中一个复选框(如果选中了另一个复选框,则应取消选中该复选框-例如Radiobutton).因此,我将从Checkbox中获取网格的行数据.
,有人可以建议如何提出上述要求.
非常感谢....
Hi,
I have a Silverlight grid, which is having a Checkbox column, currently the user can select multiple rows. But the silverlight grid should allow only one checkbox to be selected(If another selected the other should deselect - like Radiobutton). So i will get the row data of grid from Checkbox checked.
, Can anybody suggest how to make the above requriement.
Many thanks....
推荐答案
最简单的方法-在复选框数据源中运行一个循环(假设您的绑定是两种方式).
Easiest way - run a loop through the checkbox datasource (assuming your binding is two way).
Check the one selected and remove the selection on the others.
CheckBox previousCheckBox = null;
private void chkPerson_Click(object sender, RoutedEventArgs e)
{
if(previousCheckBox!=null)
{
previousCheckBox.IsChecked = false;
}
CheckBox currentCheckBox = sender as CheckBox;
previousCheckBox = currentCheckBox;
}
private void chkPerson_Unchecked(object sender, RoutedEventArgs e)
{
previousCheckBox = null;
}
这篇关于如何使Silverlight Grid仅允许选择一个复选框.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文