Skip to main content
A newer version of this page is available. .

RepositoryItemRadioGroup.Items Property

Gets the collection of items displayed by the current radio group editor.

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v18.2.dll

Declaration

[DXCategory("Data")]
public RadioGroupItemCollection Items { get; }

Property Value

Type Description
RadioGroupItemCollection

The RadioGroupItemCollection object representing the collection of items displayed by the editor.

Remarks

The Items property provides access to the collection of items displayed in a radio group. You can use the methods of the RadioGroupItemCollection class to add, remove and access individual items.

Elements in the collection can be of any type. To add an item to the collection, use the RadioGroupItemCollection.Add, RadioGroupItemCollection.AddRange and RadioGroupItemCollection.Insert methods.

Note: for the editor to function correctly, items in the collection must be unique objects.

The index of the item currently selected can be obtained or set via the RadioGroup.SelectedIndex property.

At design time, you can add items using the standard String Collection Editor which can be invoked in the Properties window.

Example

This example demonstrates how to programmatically create a radio group, add two items to the collection, initialize their properties and assign a handler to the RadioGroup.SelectedIndexChanged event. The created radio group will be used to control the visibility of a standard button control. This example assumes that a button has already been placed on the form.

The image below shows the example application.

RadioGroupCtor-Example

using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Controls;

private void CreateRadioEditors() {
    // creating and initializing the radio group items
    RadioGroupItem item1 = new RadioGroupItem();
    item1.Description = "Hide Button";
    RadioGroupItem item2 = new RadioGroupItem();
    item2.Description = "Show Button";
    // creating and initializing the radio group editor
    RadioGroup radioEdit1 = new RadioGroup();
    radioEdit1.Properties.Items.Add(item1);
    radioEdit1.Properties.Items.Add(item2);
    radioEdit1.Name = "radioEdit1";
    radioEdit1.Location = new System.Drawing.Point(30, 35);
    radioEdit1.Width = 100;
    radioEdit1.Height = 100;
    // setting the editor's selection depending upon the button's visibility
    if (button1.Visible) radioEdit1.SelectedIndex = 1;
    // assigning a handler for the SelectedIndexChanged event of the editor
    radioEdit1.SelectedIndexChanged += new EventHandler(SelectedIndexChanged);
    this.Controls.Add((Control)radioEdit1);
}

private void SelectedIndexChanged(object sender, System.EventArgs e) {
    RadioGroup edit = sender as RadioGroup;
    if (edit.SelectedIndex == 0) button1.Visible = false;
    else button1.Visible = true;
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the Items property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also