0

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.

A.K.
  • 3,321
  • 1
  • 15
  • 27
Srihari
  • 2,387
  • 9
  • 51
  • 82

1 Answers1

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");
    }
}
cse
  • 4,066
  • 2
  • 20
  • 37
Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189
  • error showing on this line `int editValue = (int)barEditItem1.EditValue;` as Specified cast is not valid. – Srihari Dec 13 '13 at 13:59
  • @SriHari As I shown you you should add `RadioGroupItem` like this. Look at the first parameter, it is integer. What you have added? – Sriram Sakthivel Dec 13 '13 at 15:52
  • Hi, Sriram thanks I got now. In RadioGroup Item Value i used string before so error came now I changed and get expected result. Thanks a lot. – Srihari Dec 14 '13 at 05:52
  • Hi Sriram, I have another doubt I want to store this radio Button to access database and want to retrieve it. [How2Store](http://stackoverflow.com/questions/20593344/how-to-store-and-retrieve-the-radiogroup-radio-button-and-checkbox-of-ribbon-con) – Srihari Dec 16 '13 at 05:18
  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Tiago Martins Peres Oct 26 '18 at 09:31