> For the complete documentation index, see [llms.txt](https://docs-siticoneframework.gitbook.io/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-siticoneframework.gitbook.io/home/net-framework-or-net-core-ui/chip-and-group-controls/siticone-groupchip/group-management.md).

# Group Management

A mechanism that allows the chip to be assigned to a group so that chips in the same group behave like radio buttons, ensuring only one chip is selected at a time.

## Overview

The Group Management feature in the chip control enables developers to group multiple chip instances by setting the `Group` property. When chips share the same group identifier, they work together to enforce a single-selection behavior similar to radio buttons. The control also provides the `GroupChanged` event to notify applications when a chip’s group is modified, allowing dynamic responses to changes in grouping.

***

### Key Points

| Aspect             | Details                                                                                                                                     |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------- |
| Property           | **Group**: A string identifier that assigns the chip to a specific group.                                                                   |
| Behavior           | Chips sharing the same group behave like a radio button group, meaning selecting one chip will automatically deselect others in that group. |
| Event Notification | **GroupChanged**: An event that is fired whenever the chip's group property changes, providing a hook for additional application logic.     |
| Integration        | Useful for managing mutually exclusive selections in scenarios such as filtering options, settings toggles, or segmented controls.          |

***

### Best Practices

| Practice                          | Explanation                                                                                                                                              |
| --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Use meaningful group names        | Assign descriptive group names (e.g., "PaymentMethods" or "ColorOptions") to maintain clarity when managing multiple chip groups in your application.    |
| Handle the GroupChanged event     | Subscribe to the `GroupChanged` event to trigger necessary UI updates or logic when chips change groups dynamically.                                     |
| Enforce single selection manually | Although chips in the same group behave like radio buttons, consider additional application logic if your requirements demand custom selection behavior. |

#### Code Example: Setting and Handling Group Management

```csharp
// Creating two chips and assigning them to the same group.
var chip1 = new SiticoneGroupChip();
var chip2 = new SiticoneGroupChip();

// Set the Group property for both chips.
chip1.Group = "PaymentMethods";
chip2.Group = "PaymentMethods";

// Subscribe to the GroupChanged event.
chip1.GroupChanged += (sender, e) =>
{
    Console.WriteLine($"Chip 1 group changed to: {e.NewGroup}");
};

chip2.GroupChanged += (sender, e) =>
{
    Console.WriteLine($"Chip 2 group changed to: {e.NewGroup}");
};

// Dynamically change the group at runtime.
chip1.Group = "AlternativeMethods";
```

***

### Common Pitfalls

| Pitfall                      | Explanation                                                                                                                                       |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| Inconsistent group naming    | Using similar but non-identical group names (e.g., "GroupA" vs. "groupA") can lead to unexpected behavior since group matching is case-sensitive. |
| Not subscribing to events    | Ignoring the `GroupChanged` event might result in missed opportunities to update related UI elements when the grouping changes.                   |
| Overcomplicating group logic | Over-engineering the grouping logic when simple radio-button behavior is sufficient can make the integration unnecessarily complex.               |

#### Code Example: Avoiding Pitfalls

```csharp
// Ensure consistent naming for grouping.
const string paymentGroup = "PaymentMethods";

var chipA = new SiticoneGroupChip { Group = paymentGroup };
var chipB = new SiticoneGroupChip { Group = paymentGroup };

// Proper event subscription to update UI if needed.
chipA.GroupChanged += OnChipGroupChanged;
chipB.GroupChanged += OnChipGroupChanged;

void OnChipGroupChanged(object sender, GroupChangedEventArgs e)
{
    // Handle group change logic here.
    Console.WriteLine("Group changed to: " + e.NewGroup);
}
```

***

### Usage Scenarios

| Scenario                        | Description                                                                                                                           |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| Payment Option Selection        | Group chips representing different payment options so that the user can only select one method at a time.                             |
| Survey or Questionnaire Options | Use chips to present mutually exclusive answers, ensuring only one answer is selected per question.                                   |
| Filter or Category Selection    | When displaying categories (e.g., product filters), grouping chips ensures only one filter is active, simplifying the user interface. |

#### Code Example: Payment Option Selection

```csharp
// Create chip instances for different payment methods.
var chipCreditCard = new SiticoneGroupChip { Text = "Credit Card", Group = "PaymentMethods" };
var chipPayPal = new SiticoneGroupChip { Text = "PayPal", Group = "PaymentMethods" };
var chipApplePay = new SiticoneGroupChip { Text = "Apple Pay", Group = "PaymentMethods" };

// Add chips to a form panel.
panelPaymentOptions.Controls.Add(chipCreditCard);
panelPaymentOptions.Controls.Add(chipPayPal);
panelPaymentOptions.Controls.Add(chipApplePay);
```

***

### Real Life Usage Scenarios

| Real Life Scenario          | Example                                                                                                                            |
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| Online Checkout Forms       | Use grouped chips to allow the user to select a single payment method during the checkout process.                                 |
| Mobile Application Settings | Implement grouped chips in settings menus where only one configuration option can be active at a time (e.g., notification sounds). |
| Dashboard Filters           | Create filters for a dashboard where each chip represents a different data category, enforcing a single filter selection.          |

#### Code Example: Dashboard Filter Chips

```csharp
// Create chips for dashboard filtering.
var chipAllData = new SiticoneGroupChip { Text = "All", Group = "DashboardFilters" };
var chipCategoryA = new SiticoneGroupChip { Text = "Category A", Group = "DashboardFilters" };
var chipCategoryB = new SiticoneGroupChip { Text = "Category B", Group = "DashboardFilters" };

// Add chips to a filter panel.
filterPanel.Controls.Add(chipAllData);
filterPanel.Controls.Add(chipCategoryA);
filterPanel.Controls.Add(chipCategoryB);
```

***

### Troubleshooting Tips

| Tip                               | Details                                                                                                                               |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| Verify Group Property Consistency | Ensure that the `Group` property is set consistently across chips; check for typos or case differences.                               |
| Check Event Subscriptions         | Make sure that event handlers for `GroupChanged` are correctly attached to catch group modification events.                           |
| Debug Selection Behavior          | If multiple chips appear selected, review the logic handling the `IsSelected` property and group logic to confirm only one is active. |

***

### Review

<table><thead><tr><th width="227">Review Aspect</th><th>Comments</th></tr></thead><tbody><tr><td>Functionality</td><td>The Group Management feature is straightforward and leverages familiar radio-button behavior to manage chip selection across groups.</td></tr><tr><td>Ease of Integration</td><td>Integration is simple: set the <code>Group</code> property, subscribe to <code>GroupChanged</code>, and the control manages selection automatically.</td></tr><tr><td>Flexibility</td><td>Developers can easily switch groups at runtime and combine this feature with custom event handling for dynamic UI updates.</td></tr></tbody></table>

***

### Summary

The Group Management feature provides a powerful way to organize and manage multiple chip controls by assigning them to logical groups. With a single property (`Group`) and an event (`GroupChanged`), developers can implement mutually exclusive selection behavior with minimal effort. This feature is ideal for scenarios such as payment options, survey answers, and filter selections, making it a versatile tool for a wide range of applications.

***

### Additional Sections

#### Integration Checklist

| Item                       | Check                                                                               |
| -------------------------- | ----------------------------------------------------------------------------------- |
| Group property assigned    | Ensure that each chip has a properly assigned and consistent group identifier.      |
| Event handlers attached    | Confirm that the `GroupChanged` event is subscribed to for dynamic updates.         |
| Testing selection behavior | Test that selecting one chip in a group deselects any other chip in the same group. |

#### FAQ

| Question                              | Answer                                                                                                                |
| ------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| What happens if no group is assigned? | The chip behaves as a standalone control without the mutual exclusion behavior of a group.                            |
| Can the group be changed at runtime?  | Yes, the `Group` property can be updated dynamically and the control will raise the `GroupChanged` event accordingly. |

***

This extensive documentation for the Group Management feature should assist developers in understanding, integrating, and troubleshooting this functionality within their .NET WinForms applications.
