Back to Devexpress

RadioGroup.SelectedIndex Property

windowsforms-devexpress-dot-xtraeditors-dot-radiogroup-9c24977e.md

latest8.1 KB
Original Source

RadioGroup.SelectedIndex Property

Gets or sets the selected item’s index.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue(-1)]
[DXCategory("Appearance")]
public int SelectedIndex { get; set; }
vb
<DefaultValue(-1)>
<DXCategory("Appearance")>
Public Property SelectedIndex As Integer

Property Value

TypeDefaultDescription
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.

csharp
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;
        }
}
vb
Private radioGroup1.KeyDown += AddressOf RadioGroup1_KeyDown

Private Sub RadioGroup1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
    Dim radioGroup = TryCast(sender, RadioGroup)
    If e.Control Then
        Select Case e.KeyCode
            Case Keys.D1
                radioGroup.SelectedIndex = 0
            Case Keys.D2
                radioGroup.SelectedIndex = 1
        End Select
    End If
End Sub

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.

winforms-richedit-use-images-in-mail-merge/CS/MergeSimpleDataForm.cs#L35

csharp
MergeRecords GetMergeRecords() {
    switch(this.rgMergeRecords.SelectedIndex){
        case 0:

winforms-grid-use-layoutview-as-master-view/CS/WindowsApplication3/Form1.cs#L34

csharp
radioGroup1.Properties.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem(ViewType.Card, "Card"));
    radioGroup1.SelectedIndex = 0;
}

winforms-pivot-grid-hide-specific-columns-and-rows/CS/Form1.cs#L26

csharp
if (pivot.DataSource == null) return;
if (radioGroup1.SelectedIndex == 0) return;

winforms-pivot-split-field-value-cells/CS/Form1.cs#L24

csharp
if (pivot.DataSource == null) return;
if (radioGroup1.SelectedIndex == 0) return;

winforms-pivot-grid-hide-empty-columns-and-rows/CS/Form1.cs#L19

csharp
protected void pivotGrid_CustomFieldValueCells(object sender, PivotCustomFieldValueCellsEventArgs e) {
    if (radioGroup1.SelectedIndex == 0) return;
    HideEmptyValues(true, e);

winforms-richedit-use-images-in-mail-merge/VB/MergeSimpleDataForm.vb#L81

vb
Private Function GetMergeRecords() As MergeRecords
    Select Case rgMergeRecords.SelectedIndex
        Case 0

winforms-grid-use-layoutview-as-master-view/VB/WindowsApplication3/Form1.vb#L35

vb
radioGroup1.Properties.Items.Add(New DevExpress.XtraEditors.Controls.RadioGroupItem(ViewType.Card, "Card"))
    radioGroup1.SelectedIndex = 0
End Sub

winforms-pivot-grid-hide-specific-columns-and-rows/VB/Form1.vb#L29

vb
End If
If radioGroup1.SelectedIndex = 0 Then
    Return

winforms-pivot-split-field-value-cells/VB/Form1.vb#L26

vb
End If
If radioGroup1.SelectedIndex = 0 Then
    Return

winforms-pivot-grid-hide-empty-columns-and-rows/VB/Form1.vb#L23

vb
Protected Sub pivotGrid_CustomFieldValueCells(ByVal sender As Object, ByVal e As PivotCustomFieldValueCellsEventArgs)
    If radioGroup1.SelectedIndex = 0 Then Return
    HideEmptyValues(True, e)

See Also

SelectedIndexChanged

Items

EditValue

RadioGroup Class

RadioGroup Members

DevExpress.XtraEditors Namespace