Bind an enumeration to combobox in WinForm

In this post, we will learn about how to Bind an enumeration to combobox in WinForm with an example.

Description:

In my previous posts I have explained various topics like Get site visitor count in asp.net
Convert generic list to datatable in Asp.Net C#.Net, Abstract Class in C# with Example,
Routing in Asp.Net MVC with Example
,Use of Global.asax in Asp.net




Now in this post, I will explain how to Bind an enumeration to combobox in WinForm with appropriate example. You can read about benefits of enumeration here.
Now create WinForm application in Visual Studio and write below lines of code in it.

using System;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        enum SiteList
        {
            DotNetK = 1,
            Live24u = 2,
            w3school = 3
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cbSiteList.DataSource = Enum.GetValues(typeof(SiteList)).Cast<SiteList>().Select(p => new { Key = (int)p, Value = p.ToString() }).ToList();

            cbSiteList.DisplayMember = "Value";
            cbSiteList.ValueMember = "Key";
        }
    }
}

Bind an enumeration to combobox in WinForm

Bind an enumeration to combobox in WinForm





Read :

Summary

You can also read about ASP.NET, C#.Net, JQUERY, AJAX, JavaScript
I hope you get an idea about how to Bind an enumeration to combobox in WinForm.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you liked this post, don’t forget to share this.

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *
Website