MListBox
Home
Components
MListBox
About component
MListBox is component for displaying a continuous group of text or images. It is composed of items containing primary and supplemental actions, which are represented by icons and text.
How to use it?
Like other controls, MListBox can be simply droped from toolbox on the form. If you are not using IDE with integrated form designer (like Visual Studio), you can always create list-box programmatically:
// Initialize list-box first
MListBox listBox = new MListBox();
// Set location
listBox.Location = new Point(50, 50);
// Don't forget to add our newly created
// check-box to form's control collection.
targetForm.Controls.Add(listBox);
using System;
using System.Windows.Forms;
using Minimal.Components;
namespace Demo
{
public partial class MyForm : Form
{
// Initialize list-box first
MListBox listBox = new MListBox();
// Form constructor
public MyForm()
{
InitializeComponent();
// Add size and location
listBox.Location = new Point(50, 50);
// Don't forget to add our newly created
// list-box to form's control collection.
Controls.Add(listBox);
}
}
}
Code example asumes, that targetForm variable is form where you want to have your button placed. If you are working inside a class derived from System.Windows.Forms.Form, you can of course replace targetForm variable with this keyword or in latest version of C# omit form reference completely. See second example.
What has changed?
In addition to all standard list-box functions you can now filter items using Filter property. Items from Items collection which match given filter are then pushed to the DisplayedItems collection, which is finally presented to the user. Filter and item are being compared based on PrimaryText of an item.
Filter is not case sensitive.
// Items added for testing purposes
listBox.Items.Add("Prague");
listBox.Items.Add("Paris");
listBox.Items.Add("Palermo");
listBox.Items.Add("New York");
// Set filter to "P"
// Prague, Paris and Palermo are now visible items for the user.
listBox.Filter = "P";
// Items => Prague, Paris, Palermo, New York
// DisplayedItems => Prague, Paris, Palermo
// Set filter to "Pr"
// Only Prague is now visible for the user.
listBox.Filter = "P";
// Items => Prague, Paris, Palermo, New York
// DisplayedItems => Prague
Adding items
Items can be added using Items property. You can pass only objects derived from MItem class. Those are for example SingleLineItem or TwoLineItem.
// Creates new single line item
SingleLineItem item = new SingleLineItem("Item 1");
// Adds item to items collection - Items property
listBox.Items.Add(item);
// Creates new two line item
TwoLineItem item = new TwoLineItem("Item 1", "This is secondary text");
// Adds item to items collection - Items property
listBox.Items.Add(item);
Thanks to an implicit conversion between MItem and string you can pass strings directly to Items.Add() method and it will be converted to single line item automatically. See example below.
// Adds new single line item to combo-box
listBox.Items.Add("Item 1");
There are of course cases where single line or two line items do not fit your needs. In that scenario you can inherit from MItem class and design your own item. See MItem class documentation for more. If MultiSelect is on, user can select multiple items by holding ctrl key and clicking. Selected items then live in SelectedItems collection.
Class content
Assembly |
Minimal.dll |
Namespace |
Minimal.Components |
Inheritance |
MScrollablePanel |
Attributes |
Minimal.Components.Design.ListBoxDesigner |
Implements |
IMComponent |
This list doesn’t include content derived from the parent class. See MScrollablePanel class documentation for a complete list of items.
Constructors
Name |
Description |
|
MListBox() |
Initializes a new instance of the MListBox class. |
|
Properties
Name |
Description |
Type |
Component |
Handles life-cycle of the M-Component. |
MComponent |
Items |
Collection of list-box's items. |
ObservableCollection<MItem> |
DisplayedItems |
Items displayed when Filter property is assigned. |
ObservableCollection<MItem> |
SelectedItem |
Selected item from the list-box. |
MItem |
MultiSelect |
User can select multiple items at once using CTRL key + click if enabled. |
bool |
SelectedItems |
List of all selected items of the list-box. MultiSelect must be enabled. |
bool |
Accent |
Component’s accent color. Main visible color of the component. |
Color |
ClickEffect |
Click effect of the button. Occurs on component click. |
ClickEffect |
CustomTheme |
Component’s custom theme. Will override default parent M-form theme or application wide theme. |
Theme |
Filter |
Filters all items in the Items collection. DisplayedItems collection is then presented to the user. |
Theme |
Fields
Name |
Description |
Type |
- |
- |
- |
Events
Name |
Description |
Type |
SelectedItemChanged |
Fires when the SelectedItem property is changed. |
PropertyChangedEventHandler |
AccentChanged |
Fires when the Accent property is changed. |
PropertyChangedEventHandler |
ClickEffectChanged |
Fires when the ClickEffect property is changed. |
PropertyChangedEventHandler |
CustomThemeChanged |
Fires when the CustomTheme property is changed. |
PropertyChangedEventHandler |
Methods
Name |
Description |
Returns |
ScrollToItem(MItem item) |
Scrolls to given item. Returns false if item is not found. Otherwise returns true. |
bool |
FindItems(string primaryText) |
Returns all items with passed primary text. |
List<MItem> |
Clear() |
Clears both Items and DisplayedItems collections. Resets SelectedItem property. |
- |