windowsforms-devexpress-dot-xtrabars-dot-barbasebuttonitem.md
Gets or sets the button’s group index. This property is in effect when the current object acts as a check button.
Namespace : DevExpress.XtraBars
Assembly : DevExpress.XtraBars.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DefaultValue(0)]
public virtual int GroupIndex { get; set; }
<DefaultValue(0)>
Public Overridable Property GroupIndex As Integer
| Type | Default | Description |
|---|---|---|
| Int32 | 0 |
The button’s group index.
|
The GroupIndex property allows you to create a radio group of check buttons. When a user selects one item, other items in the group are automatically deselected.
The GroupIndex property is in effect for BarBaseButtonItems that act like check buttons. These items include the following:
To combine two or more check buttons in a radio group, set the GroupIndex property for these buttons to the same non-zero value.
The BarBaseButtonItem.AllowAllUp property determines if all items in a group can be deselected simultaneously.
The following code combines two BarCheckItems in a radio group.
private void Form1_Load(object sender, EventArgs e) {
int colorRadioGroupValue1 = 11;
barCheckItem1.Caption = "Black";
barCheckItem1.CheckBoxVisibility = CheckBoxVisibility.BeforeText;
barCheckItem1.CheckStyle = BarCheckStyles.Radio;
barCheckItem1.GroupIndex = colorRadioGroupValue1;
barCheckItem1.CheckedChanged += BarCheckItem_CheckedChanged;
barCheckItem2.Caption = "White";
barCheckItem2.CheckBoxVisibility = CheckBoxVisibility.BeforeText;
barCheckItem2.CheckStyle = BarCheckStyles.Radio;
barCheckItem2.GroupIndex = colorRadioGroupValue1;
barCheckItem2.CheckedChanged += BarCheckItem_CheckedChanged;
barCheckItem2.Checked = true;
}
private void BarCheckItem_CheckedChanged(object sender, ItemClickEventArgs e) {
BarCheckItem checkItem = sender as BarCheckItem;
MessageBox.Show(checkItem.Caption);
}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim colorRadioGroupValue1 As Integer = 11
BarCheckItem1.Caption = "Black"
BarCheckItem1.CheckBoxVisibility = CheckBoxVisibility.BeforeText
BarCheckItem1.CheckStyle = BarCheckStyles.Radio
BarCheckItem1.GroupIndex = colorRadioGroupValue1
AddHandler BarCheckItem1.CheckedChanged, AddressOf BarCheckItem_CheckedChanged
BarCheckItem2.Caption = "White"
BarCheckItem2.CheckBoxVisibility = CheckBoxVisibility.BeforeText
BarCheckItem2.CheckStyle = BarCheckStyles.Radio
BarCheckItem2.GroupIndex = colorRadioGroupValue1
AddHandler BarCheckItem2.CheckedChanged, AddressOf BarCheckItem_CheckedChanged
BarCheckItem2.Checked = True
End Sub
Private Sub BarCheckItem_CheckedChanged(ByVal sender As Object, ByVal e As ItemClickEventArgs)
Dim checkItem As BarCheckItem = TryCast(sender, BarCheckItem)
MessageBox.Show(checkItem.Caption)
End Sub
See Also