Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Getting unexpected behavior when examining the IsChecked property of a Checkbox

$
0
0

We have 6 checkboxes on a user control. We want to be able to determine, whetjher or not each of the 6 boxes are checked. We tried doing this in this event in the code behind:

private const short Black = 1;
private const short White = 32;
private const short Asian = 2;
private const short Islander = 8;
private const short AmInd = 4;
private const short Alask = 16;

private void RaceCheckboxes_Checked(object sender, System.Windows.RoutedEventArgs e)
{
	short race = 0;

	if (cbAlask.IsChecked == true)
	{
	    race += Alask;
	}
	if (cbAmInd.IsChecked == true)
	{
	    race += AmInd;
	}
	if (cbIslander.IsChecked == true)
	{
	    race += Islander;
	}
	if (cbAsian.IsChecked == true)
	{
	    race += Asian;
	}
	if (cbWht.IsChecked == true)
	{
	    race += White;
	}
	if (cbBlack.IsChecked == true)
	{
	    race += Black;
	}

	atr.Race = race;
}

The thing I don't understand is this. When the user clicks on the checkbox named cbWht, it entered this event and all 6 of the checkboxes IsChecked property were true. Why is that? Only 1 of them was checked.

Rod


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>