嗨,我需要在Ribbon控件上使用RadioButton,所以我使用了RadioGroup并创建了事件selectedIndexChanged
,其中我执行了一些任务
private void repositoryItemRadioGroup1_SelectedIndexChanged(object sender, EventArgs e)
{
RadioGroup rg = (RadioGroup)sender;
int index = rg.SelectedIndex;
if (index == 0)
{
// code
}
if (index == 1)
{
// code
}
if (index == 2)
{
// code
}
else if (!(index == 2) || !(index == 1))
{
// code
}
}
直到现在代码工作正常。在beforeLeaveRow
事件中我正在执行一些计算,但我需要根据所选的单选按钮执行计算,所以我需要获取选定单选按钮然后执行基于的计算我选择了什么。
例如
private void gridView1_BeforeLeaveRow(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e)
{
decimal a = Convert.ToDecimal(TXE_SubTotal.Text);
decimal b = Convert.ToDecimal(TXE_Shipping.Text);
decimal c = Convert.ToDecimal(TXE_Tax.Text);
decimal d = Convert.ToDecimal(TXE_Discount.Text);
if(RadioGroup.index==0)
{
total = ((a + b + c) - d).ToString("n2");
}
else if(RadioGroup.index==1)
{
total = (a + b + c).ToString("n2");
}
}
我需要执行这样的计算。帮我完成任务。如何获取选择的RadioIndex或其他东西??
提前致谢。
答案 0 :(得分:1)
以下是所需的代码:
repositoryItemRadioGroup1.Items.AddRange(new RadioGroupItem[]
{
new RadioGroupItem(1, "Item1"),
new RadioGroupItem(2, "Item2")
});
private void gridView1_BeforeLeaveRow(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e)
{
if(barEditItemRadio.EditValue==null)
return;//Or do whatever
int editValue = (int)barEditItemRadio.EditValue;
if(editValue ==1)//Item1 is selected
{
total = ((a + b + c) - d).ToString("n2");
}
else if(editValue ==2)//Item2is selected
{
total = (a + b + c).ToString("n2");
}
}