C# MetroFramework - MetroListView - Fill From Dictionary

| Page Views: 562

So in this example we wanna see how to populate a metrolistview with data from Dictionary.

We use Dictionary Collection as our data source and fill our multicolumn metroListView with data.

We also see how to handle our MetroListView's ItemSelectionChanged events thus showing the ListView's selected item in a messagebox.

Example Demo

Let's start.

1. Create Empty Project

  1. Open up Visual Studio and proceed over to File --> New Project

  2. A new dialog popus up like this:

Create Project

  1. Give our empty project a name and click OK. An empty project will get generated for us.

2. Install Metro Framework

If you haven't installed it yet. If you have then just add reference dlls to your project.

  1. Right click the references section of your project and select manage nuget packages.A dialog popups up.

  2. Search "Metro Framework" by Dennis Magno and click install as below.

Install MetroFramewok

3. Add Metro Framework DLLs to Project

We now need to add metro framework dlls to our project to use metro framework.

  1. Next right click the references section of your project and add the metroframework dlls from the packages directory onto which they were installed. You may need to search that directory in your computer.

Add MetroFramewok DLLs

  1. You should have it like these:

MetroFramewok References

4. Make project a Windows Project

Just right click on your project choose properties and set output type to Windows Application:

MetroFramewok References

5. Program.cs

We have one class, Program.cs.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using MetroFramework.Controls;
using MetroFramework.Forms;

namespace MetroListViewDictionary
    static class Program
        private static MetroListView metroListView;
        public static void Main()

        private static void createMetroForm()
            MetroForm myForm = new MetroForm
                Text = "MetroListView Dictionary - Nebulae",
                ClientSize = new Size(564, 520)

        private static void setupListView()
            metroListView = new MetroListView { Location = new Point(30, 70), Size = new Size(400, 400), View = View.Details, FullRowSelect = true, Alignment = ListViewAlignment.SnapToGrid };
            metroListView.Columns.Add("NEBULAR", 200);
            metroListView.Columns.Add("CATEGORY", 200);
            metroListView.MultiSelect = false;
            metroListView.ItemSelectionChanged += metroListView_ItemSelectionChanged;

        static void metroListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
            if (e.IsSelected)
                ListViewItem listViewItem = e.Item;

        private static void populateData()
            Dictionary<String, String> nebulae = new Dictionary<String, String>
                { "Horse Head","HII REGION"},
                {"Black Widow","REFLECTION NEBULAR"},
                { "Ghost Head","HII REGION"},
                { "Witch Head" ,"PLANETARY NEBULAR"},
                { "Cat's Eye","DARK NEBULAR"},
                { "Elephant's Trunk","HII REGION"},
                { "Helix", "SUPERNOVA REMNANTS"},
                { "Rosette","REFLECTION NEBULAR"},
                { "Ant","PLANETARY NEBULAR"},
                { "Orion","HII REGION"},
                { "Eagle","REFLECTION NEBULAR"},
                { "Roesette","PLANETARY NEBULAR"},
                { "Bernad 68","SUPERNOVA REMNANTS"},
                { "Butterfly","DARK NEBULAR"},
                { "Snake","DARK NEBULAR"},
                { "Own","REFLECTION NEBULAR"},
                { "Ring", "SUPERNOVA REMNANTS"},
                { "Pelican","PLANETARY NEBULAR"},
                { "Cone","DARK NEBULAR"},
                { "Flame","REFLECTION NEBULAR"},
                { "Bumerang", "SUPERNOVA REMNANTS"}

            foreach (KeyValuePair<string, string> nebular in nebulae)
                metroListView.Items.Add(new ListViewItem(new[] { nebular.Key,nebular.Value  }));

Best Regards, Oclemy.

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section.

About Me.

After completing his Software Engineering bachelors program, Oclemy(Clement Ochieng) these days is a man of two lives. At day he works for a startup in Nairobi, Kenya. At night he works tirelessly on building ProgrammingWizards TV, a tv channel for student coders and this website to help share the source code. In between he practices Meditation and Self actualization to help him keep balance. He also likes going for long solo walks to connect more with nature.


What do You Think

Previous Post Next Post