问题
Hi, I need RadioButton on Ribbon Control so I used RadioGroup and created event selectedIndexChanged
, In which I performed some tasks
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
}
}
Till now the code work fine.in beforeLeaveRow
event I am performing some calculations but I need to perform the calculations based on the Radio Button Selected so I need to get that Selected Radio Button and then perform calculations based on what I selected.
eg
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");
}
}
I need to perform calculations like this. Help me complete my task. How to get Selected RadioIndex or something ??
Thanks in advance.
回答1:
Following is desired code:
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");
}
}
来源:https://stackoverflow.com/questions/20567669/how-to-work-with-radiogroup-in-ribboncontrol-in-winforms-devexpress