ListBox
Grouping
Features
Sample
ListBox Grouping
Use the showGroups property to add group headers to ListBox controls.
Group header items are added if the showGroups property is set to true and the itemsSource collection has grouping enabled.
Header items are presentational only. They cannot be selected with the mouse or keyboard and are not bound to any data items.
Description
This sample shows how to show group items of the ListBox control.
Source
GroupingController.cs
using MvcExplorer.Models; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MvcExplorer.Controllers { public partial class ListBoxController : Controller { // GET: Grouping public ActionResult Grouping() { var nwind = new C1NWindEntities(); return View(nwind.Suppliers.Take(20)); } } }
Grouping.cshtml
@model IEnumerable<Supplier> @(Html.C1().CollectionViewService<Supplier>().Bind(Model).Id("collectionViewService").GroupBy("Country")) <div> <h2> @Html.Raw(Resources.ListBox.Grouping_Text0) </h2> <p> @Html.Raw(Resources.ListBox.Grouping_Text1) </p> <p> @Html.Raw(Resources.ListBox.Grouping_Text2) </p> <p> @Html.Raw(Resources.ListBox.Grouping_Text3) </p> </div> <div> @(Html.C1().ListBox() .ShowGroups(true) .DisplayMemberPath("CompanyName") .ItemsSourceId("collectionViewService") .Width(250).Height(200)) </div> @section Description{ @Html.Raw(Resources.ListBox.Grouping_Text4) }
Documentation