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)
{
}
}
我遇到了这个问题,我在 Datagrid 中绑定(bind)了复选框,当我们单击复选框时,我正在做一些简单的数学计算,它应该在文本框中添加总和,它正在这样做,但问题是鼠标上下滚动自动选中和取消选中复选框,现在文本框中所选项目的总价更高,所选复选框更少或有时更多,因此鼠标向上或向下滚动会产生此问题。任何想法???? 谢谢
最佳答案
您需要在您的网格中设置 VirtualizingStackPanel.IsVirtualizing="False"
!
关于c# - 鼠标滚动选中和取消选中 DataGrid 中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8577714/