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.

READ :  C# Queue Tutorial with Examples

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.

[php]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”;
}
}
}
[/php]

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 :  Angularjs cookie Set Cookie Get Cookie Delete Cookie Example

Leave a Comment