Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8919853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:07:39+00:00 2026-06-15T06:07:39+00:00

I would like to use multiple radio groups within a single rootelelement with monotouch

  • 0

I would like to use multiple radio groups within a single rootelelement with monotouch dialog. Each radiogroup would have its own section. I can’t find a way to make this work because a single radiogroup can only be assigned to the rootelement

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:07:41+00:00Added an answer on June 15, 2026 at 6:07 am

    svn!

    Here is my solution

    public class CustomRootElement : RootElement
    {
        private RadioGroup _defaultGroup = new RadioGroup(0);
        private Dictionary<string, RadioGroup> _groups = new Dictionary<string, RadioGroup>();
    
        public CustomRootElement(string caption = "") : base(caption , new RadioGroup("default",0))
        {
        }
    
        public CustomRootElement(string caption, Group group, Func<RootElement, UIViewController> createOnSelected) : base(caption, group)
        {
    
            var radioGroup = group as RadioGroup;
    
            if(radioGroup != null)
            {
                _groups.Add(radioGroup.Key.ToLower(), radioGroup);
            }
    
            this.createOnSelected = createOnSelected;
        }
    
    
    
        public override UITableViewCell GetCell(UITableView tv)
        {
            var cell =  base.GetCell(tv);
    
            cell.SelectionStyle = UITableViewCellSelectionStyle.None;
    
            return cell;
        }
    
        public int Selected(string group)
        {
            if (string.IsNullOrEmpty(group))
            {
                throw new ArgumentNullException("group");
            }
    
            group = group.ToLower();
            if (_groups.ContainsKey(group))
            {
                return _groups[group].Selected;
            }
    
            return 0;
        }
    
        public void Select(string group, int selected)
        {
            if (string.IsNullOrEmpty(group))
            {
                throw new ArgumentNullException("group");
            }
    
            var radioGroup = GetGroup(group);
            radioGroup.Selected = selected;
        }
    
        internal RadioGroup GetGroup(string group)
        {
            if (string.IsNullOrEmpty(group))
            {
                throw new ArgumentNullException("group");
            }
    
            group = group.ToLower();
            if (!_groups.ContainsKey(group))
            {
                _groups[group] = new RadioGroup(group , 0);
            }
    
            return _groups[group];
        }
    
        internal NSIndexPath PathForRadioElement(string group, int index)
        {
    
            foreach (var section in this)
            {       
                foreach (var e in section.Elements)
                {
                    var re = e as SlRadioElement;
                    if (re != null 
                        && string.Equals(re.Group, group,StringComparison.InvariantCultureIgnoreCase)
                        && re.Index == index)
                    {
                        return e.IndexPath;
                    }
                }
            }
    
            return null;
        }
    
    }
    
    
    public class CustomRadioElement : RadioElement
    {
        public event Action<CustomRadioElement> ElementSelected;
    
        private readonly static NSString ReuseId = new NSString("CustomRadioElement");
        private string _subtitle;
        public int? Index  { get; protected set; }
    
        public CustomRadioElement(string caption, string group = null, string subtitle = null) :base(caption, group)
        {
            _subtitle = subtitle;
        }
    
        protected override NSString CellKey
        {
            get
            {
                return ReuseId;
            }
        }
    
        public override UITableViewCell GetCell(UITableView tv)
        {
    
            EnsureIndex();
    
            var cell = tv.DequeueReusableCell(CellKey);
            if (cell == null)
            {
                cell = new UITableViewCell(UITableViewCellStyle.Subtitle , CellKey);
            }
    
            cell.ApplyStyle(this);
    
            cell.TextLabel.Text = Caption;
            if (!string.IsNullOrEmpty(_subtitle))
            {
                cell.DetailTextLabel.Text = _subtitle;
            }
    
    
            var selected = false;
            var slRoot = Parent.Parent as CustomRootElement;
    
            if (slRoot != null)
            {
                selected = Index == slRoot.Selected(Group);
    
            }
            else
            {
                var root = (RootElement)Parent.Parent;
                selected = Index == root.RadioSelected;
            }
    
            cell.Accessory = selected ? UITableViewCellAccessory.Checkmark : UITableViewCellAccessory.None;
    
            return cell;
        }
    
        public override void Selected(DialogViewController dvc, UITableView tableView, NSIndexPath indexPath)
        {
            var slRoot = Parent.Parent as CustomRootElement;
    
            if (slRoot != null)
            {
                var radioGroup = slRoot.GetGroup(Group);
    
                if (radioGroup.Selected == Index)
                {
                    return;
                }
    
                UITableViewCell cell;
    
                var selectedIndex = slRoot.PathForRadioElement(Group, radioGroup.Selected);
                if (selectedIndex != null)
                {
                    cell = tableView.CellAt(selectedIndex);
                    if (cell != null)
                    {
                        cell.Accessory = UITableViewCellAccessory.None;
                    }
                }
    
    
                cell = tableView.CellAt(indexPath);
                if (cell != null)
                {
                    cell.Accessory = UITableViewCellAccessory.Checkmark;
                }
    
                radioGroup.Selected = Index.Value;
    
    
                var handler = ElementSelected;
                if (handler != null)
                {
                    handler(this);
                }
    
            }
            else
            {
                base.Selected(dvc, tableView, indexPath);
            }
        }
    
        private void EnsureIndex()
        {
            if (!Index.HasValue)
            {
                var parent = Parent as Section;
    
                Index = parent.Elements.IndexOf(this);
            }
        }
    }
    

    Hope this help!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say that I have a UIView which I would like to re-use in multiple
I have created a custom UIView that I would like to use on multiple
I have a AfterBuild target that I would like to use for multiple projects
I would like to use regular expressions to replace multiple groups with corresponding replacement
I would like to have multiple lines when I use jQuery's html method, like
I would like to use Multiple Y-Axis in Line chart of MS-Charts. I have
I would like to use the following class across multiple modules without needing log
I would like to use Akka to implement a multiple-readers / one-writer pattern on
I would like to use the form_for helper multiple times for the same model
I would like to use the wikipedia API to return the extract from multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.