Skip to main content

RadioGroup.SelectedIndex Property

Gets or sets the selected item’s index.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[DefaultValue(-1)]
[DXCategory("Appearance")]
public int SelectedIndex { get; set; }

Property Value

Type Default Description
Int32 -1

The selected item’s index in the RepositoryItemRadioGroup.Items collection; -1 if none selected.

Remarks

SelectedIndex returns the edit value’s zero-based index in the RepositoryItemRadioGroup.Items collection.

If you set SelectedIndex to a valid value (greater than or equal to 0 and less than the number of elements in the collection), the selection moves to the respective object from the RepositoryItemRadioGroup.Items collection. You can also set the BaseEdit.EditValue to a valid value (A System.Object value that contains any RadioGroupItem.Value fields within the collection) to achieve this.

If you set SelectedIndex to an invalid value (an index greater than the number of items), the selection moves to the last item in the collection. If the SelectedIndex is set to -1, the selection is cleared. This will also occur when you assign an invalid value to the BaseEdit.EditValue property.

When SelectedIndex changes, the RadioGroup.SelectedIndexChanged event fires.

Note: to ensure proper functionality of the editor, items in the RepositoryItemRadioGroup.Items collection must be unique objects.

The code sample below illustrates how to change the radiogroup’s selected item when users press CTRL+1 and CTRL+2.

radioGroup1.KeyDown += RadioGroup1_KeyDown;

private void RadioGroup1_KeyDown(object sender, KeyEventArgs e)
{
    var radioGroup = sender as RadioGroup;
    if(e.Control)
        switch(e.KeyCode)
        {
            case Keys.D1:
                radioGroup.SelectedIndex = 0;
                break;
            case Keys.D2:
                radioGroup.SelectedIndex = 1;
                break;
        }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the SelectedIndex 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