C# Populate Add Enum wpf combobox description binding

C# Populate Add Enum wpf combobox description binding

Today, We want to share with you C# Populate Add Enum wpf combobox description binding.
In this post we will show you Bind an enumeration to combobox in WinForm, hear for Programmatically Binding DataSource To ComboBox In Multiple Ways we will give you demo and example for implement.In this post, we will learn about Set Combobox.SelectedValue to enum value with an example.

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.

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.

READ :  Angular UI Bootstrap modals load template Solution

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
        {
            InfinityKnow = 1,
            PakaInfo = 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";
        }
    }
}

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Bind an enumeration to combobox in WinForm.
I would like to have feedback on my Infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

READ :  Overview of Implement Stack Algorithm in C#.Net

Add a Comment

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