Loading...
Loading...
Guide for implementing Syncfusion GroupView control in Windows Forms applications. Use when creating list controls with images, Visual Studio toolbox-style interfaces, or navigation item lists. Covers GroupViewItem collections, drag-drop item lists, highlighted selections, toolbox-style interfaces, and GroupBar client controls for OutlookBar-style interfaces.
npx skill4agent add syncfusion/winforms-ui-components-skills syncfusion-winforms-group-viewusing Syncfusion.Windows.Forms.Tools;
public class MyForm : Form
{
private GroupView groupView1;
private ImageList imageList1;
public MyForm()
{
InitializeComponent();
// Create GroupView
this.groupView1 = new GroupView();
this.groupView1.Location = new Point(10, 10);
this.groupView1.Size = new Size(200, 300);
this.groupView1.FlatLook = true;
// Setup ImageList
this.imageList1 = new ImageList();
this.imageList1.Images.Add(Image.FromFile("icon1.png"));
this.imageList1.Images.Add(Image.FromFile("icon2.png"));
this.imageList1.Images.Add(Image.FromFile("icon3.png"));
// Assign ImageList
this.groupView1.SmallImageList = this.imageList1;
this.groupView1.SmallImageView = true;
// Add items
this.groupView1.GroupViewItems.AddRange(new GroupViewItem[] {
new GroupViewItem("My Computer", 0, true, null, "Item0"),
new GroupViewItem("Network", 1, true, null, "Item1"),
new GroupViewItem("Recycle Bin", 2, true, null, "Item2")
});
// Handle selection event
this.groupView1.GroupViewItemSelected += GroupView1_ItemSelected;
// Add to form
this.Controls.Add(this.groupView1);
}
private void GroupView1_ItemSelected(object sender, EventArgs e)
{
int selectedIndex = this.groupView1.SelectedItem;
string selectedText = this.groupView1.GroupViewItems[selectedIndex].Text;
MessageBox.Show($"Selected: {selectedText}");
}
}// Create toolbox-style GroupView
this.groupView1.FlatLook = true;
this.groupView1.FlowView = true;
this.groupView1.ShowFlowViewItemText = true;
this.groupView1.IntegratedScrolling = true;
this.groupView1.SmallImageView = true;
this.groupView1.AllowDragDrop = true;
// Configure highlighting
this.groupView1.HighlightText = true;
this.groupView1.HighlightImage = true;
this.groupView1.HighlightItemColor = Color.LightBlue;
this.groupView1.HighlightTextColor = Color.DarkBlue;// Add single item
GroupViewItem newItem = new GroupViewItem(
text: "New Item",
imageIndex: 3,
visible: true,
toolTipText: null,
name: "NewItem1"
);
this.groupView1.GroupViewItems.Add(newItem);
// Add multiple items
this.groupView1.GroupViewItems.AddRange(new GroupViewItem[] {
new GroupViewItem("Item 1", 0, true, null, "Item1"),
new GroupViewItem("Item 2", 1, true, null, "Item2"),
new GroupViewItem("Item 3", 2, true, null, "Item3")
});// Enable highlighting
this.groupView1.HighlightText = true;
this.groupView1.HighlightImage = true;
// Set highlight colors
this.groupView1.HighlightItemColor = Color.LightGray;
this.groupView1.HighlightTextColor = Color.Black;
// Set selection colors
this.groupView1.SelectedItemColor = Color.Navy;
this.groupView1.SelectedTextColor = Color.White;
this.groupView1.SelectedHighlightItemColor = Color.Blue;
this.groupView1.SelectedHighlightTextColor = Color.Yellow;// Enable drag-and-drop
this.groupView1.AllowDragDrop = true;
this.groupView1.AllowDragAnyObject = true;
// Handle reorder event
this.groupView1.GroupViewItemsReordered += (sender, e) => {
// Items have been reordered
UpdateItemPositions();
};// Enable in-place renaming for specific item
int itemIndexToRename = 2;
this.groupView1.InplaceRenameItem(itemIndexToRename);
// Handle rename event
this.groupView1.GroupViewItemRenamed += (sender, e) => {
GroupItemRenamedEventArgs args = (GroupItemRenamedEventArgs)e;
MessageBox.Show($"Renamed from '{args.OldLabel}' to '{args.NewLabel}'");
};// Handle ShowContextMenu event
this.groupView1.ShowContextMenu += GroupView1_ShowContextMenu;
private void GroupView1_ShowContextMenu(object sender, EventArgs e)
{
ContextMenuStrip menu = new ContextMenuStrip();
// Add menu items
menu.Items.Add("Add New Item", null, AddNewItem_Click);
menu.Items.Add("Remove Item", null, RemoveItem_Click);
menu.Items.Add(new ToolStripSeparator());
menu.Items.Add("Properties", null, Properties_Click);
// Check if mouse is over an item
if (this.groupView1.ContextMenuItem != -1)
{
menu.Items[1].Enabled = true; // Enable Remove
}
else
{
menu.Items[1].Enabled = false; // Disable Remove
}
// Show context menu
menu.Show(this.groupView1, this.groupView1.PointToClient(Cursor.Position));
}