private void OnChecked(object sender, RoutedEventArgs e)
{
try
{
LAB_TEST t = new LAB_TEST();
CheckBox chk = (CheckBox)e.OriginalSource;
if (e.OriginalSource is CheckBox)
{
int OID = Convert.ToInt32(((CheckBox)chk).Tag);
t = eb.TestGetByOID(OID);
bool has = advisedTests.Any(test => test.OID == OID);
if (!has)
{
if (txtGrossAmount.Text != string.Empty)
{
decimal amount = Convert.ToDecimal(txtGrossAmount.Text);
amount += Convert.ToDecimal(t.PRICE);
txtGrossAmount.Text = amount.ToString();
}
else
{
txtGrossAmount.Text = t.PRICE.ToString();
}
advisedTests.Add(t);
}
}
}
catch (Exception ex)
{
}
}
I'm facing this problem that I've bound checkboxes in Datagrid and I'm making some simple math calculations when we click the check box it should add the sum in the textbox and it is doing this but the problem is that mouse scrolling up and down check and uncheck checkboxes automatically now the total price of the selected items in the textbox is more and selected checkboxes are less or sometimes more so mouse scrolling up or down creating this problem. Any idea???? thanks
You need set VirtualizingStackPanel.IsVirtualizing="False"
in your Grid!
I had exactly the same problem, with the following scenario :
The solution given by Jacek works, but the content is not scrollable with mouse wheel anymore, the mouse cursor has to be on the scrollbar.
What seems to work in my project is to add this property to the DataGrid
ScrollViewer.CanContentScroll="False"
It's very weird, as it tells the Datagrid not to be scrollable, BUT, the content is still scrollable via the mouse wheel, and the issue of toggling the checkboxes status doesn't happen anymore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With