How to get the value of a (DevExpress) RadioGroup

Class library usage, coding and language questions.
Lukas
Posts: 1
Joined: Tue May 15, 2007 8:40 am

How to get the value of a (DevExpress) RadioGroup

Post by Lukas » Tue May 15, 2007 8:53 am

We are using DevExpress radio group controls (DevExpress.XtraEditors.RadioGroup). Do you have any idea how I can find the selected radio button. I've tried to analyse the control but I couldn't find any values. Neither the List nor the ListItems have a value.

Child Element Name: (xy) Role: List Value: (empty) Count: 2
Child Element Name: (x) Role: ListItem Value: (empty)
Child Element Name: (y) Role: ListItem Value: (empty)

Do you have any idea how I can get to the value?

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Tue May 15, 2007 2:36 pm

If you want to find the selected radioItem use the Element.State Property like shown below….

Code: Select all

static public void DumpElementTree(Element element, int level)
{
    level++;
    int childCount = element.GetChildCount;
    for (int index = 0; index < childCount; index++)
    {
        Element child = element.GetChild(index);

        if ((child.State & State.Selected) != 0)
            Console.WriteLine("selected = " + child.Name);

        DumpElementTree(child, level);
    }

}
[STAThread]
static int Main(string[] args)
{
  ...
        Control radioGroup = form.FindControlName("radioGroupSample");
        if (radioGroup == null)
        { 
            Console.WriteLine("Cannot find radioGroup ");
            return 1;
        }

        DumpElementTree(radioGroup.Element, 0);
  ...
}
In the next version you can use the findChildren method to find elements more easier(RegularExpression …):

Code: Select all

Element[] radioItems = radioGroup.Element.FindChildren(Role.ListItem, null, null, SearchMatchMode.MatchExact);
foreach (Element item in radioItems)
{
    if ((item.State & State.Selected) != 0)
        Console.WriteLine("selected = " + item.Name);

}
Gabor
Ranorex Team