Geeks With Blogs
Tim Huffam Dotting the I and crossing the T of I.T.

This is quite simple...

Define the enum eg:

public enum MyEnum{
  ItemOne,
  ItemTwo,
}

Within the form set the datasource of the combobox to the values of the enum eg:

myCombo.DataSource = System.Enum.GetValues(typeof(MyEnum));

To have the combo auto select a value based on a bound object, set the databinding of the combo eg:

class MyObject{
  private MyEnum myEnumProperty;
  public MyEnum MyEnumProperty{get {return myEnumProperty;}}
}
MyObject myObj = new MyObject();
myCombo.DataBindings.Add(new Binding("SelectedIndex", myObject, "MyEnumProperty");

 

Posted on Wednesday, April 7, 2010 10:00 PM C# .NET , ASP.NET | Back to top


Comments on this post: Databinding a .Net WinForms ComboBox to an Enum

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
Good guidelines to follow. Thanks for your instruction.
Left by cai dat may tinh on Apr 13, 2011 9:21 PM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
That is what i'm looking for. this one is useful for any one who work with ASPX
Left by Grain Futures on Apr 15, 2011 5:19 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
I think this post will be a excellent read for my blog readers too, could you please permit me to post a link to my blog.
Left by Barelifts on May 11, 2011 9:59 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
thanks for nice post! Your instruction is very perfect. Nice guidelines.
Left by tim viec lam on May 28, 2011 4:04 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
Wow, this is really interesting. I will find out about it. Thanks.
Left by Vietnam Ailines Flights on Jun 20, 2011 11:29 PM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
thanks you!..........
Left by Sieu Thi Dien May on Aug 21, 2011 2:45 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
i think your article is very useful for me, thank for sharing
Left by Sieu Thi Dien May on Aug 21, 2011 2:46 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
Short but nice tutorial. I love it.
Left by Find out page rank, Alexa rank, on Aug 21, 2011 5:46 PM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
This really makes sense, myself have learned a lot from article, thank you for sharing.
Left by vietnam on Aug 23, 2011 11:33 PM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
The instruction is looks very good. keep hard working my friend!
Left by Gold etf trading on Sep 01, 2011 4:09 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
thansks for share!
Left by camera giám sát on Nov 08, 2011 2:58 AM

# günstige hantelbank kaufen
Requesting Gravatar...
wer will muskeln aufbauen und mit bodybuilding eine hantelbank billig kaufen? die seite http://hantelbankkaufen.de/ zeigt die besten hantelbänke
Left by hantelbänke on Nov 13, 2011 12:00 PM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
very interesting blog and a good posting !!! you must maintain your blog, its interesting !!! Thanks!
Left by Nhan Sam Han Quoc on Nov 23, 2011 3:37 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
I'll be tuning in. Thanks for the heads up!
Left by hoc tieng anh on Dec 19, 2011 2:51 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
nice posting! goodluck, thank you!
Left by noi that on Jan 11, 2012 1:21 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
Your instruction is very perfect. Nice guidelines. nice posting! goodluck, thank you!
Left by tour du lich sapa on Jan 18, 2012 8:22 PM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
Very nice post, good work !
Left by Bang & Olufsen on Feb 25, 2012 10:06 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
woww , very nice
Left by cuu ho giao thong on Mar 22, 2012 3:05 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
My group is relatively assured they have to explore an abundance of different things right in comparison with essentially everyone except for individuals!.... Sparkle great deal of visual metaphors that is certainly certainly often competent, oftentimes not likely much too understated and clean..
Left by Instagram Android on Apr 10, 2012 12:53 PM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
well! That is what i'm looking for. this one is useful for any one who work with ASPX. Thanks !
Left by EminiBroker on Apr 20, 2012 1:59 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
myself have learned a lot from article, thank you for sharing. makes sense,
Left by langeweile on May 29, 2012 12:09 PM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
Very nice post, good work !
www.4lap.vn .
chuyên buôn bán linh kiện, sửa:call_me: máy tính laptop
giá rẻ,uy tín,chất lượng cao:call_me::call_me:
Left by nguyenbahoanganh on Jul 02, 2012 3:24 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
Thank-you, that displays the "MyEnumProperty" of "MyObject", but when I select another item in the cbox, it doesn't change it in MyObject?
(PS Are email addys non-displayed here?)
Left by Graham Rounce on Oct 10, 2012 5:02 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
Hi all, nice to meet you
Left by Tai facebook on Oct 27, 2012 1:39 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
I found your site is perfect for my needs. It contains wonderful and helpful post. I have read most of them, and learned a lot from them. You do some good work. Thank you for making such a nice website.
Left by giay nam on Dec 13, 2012 4:10 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
I'm looking for this and found this website thanks only will it help me a lot
Left by Dien dan Rao vat on Jan 15, 2013 9:09 PM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
It’s very useful for me. Thanks.
Left by Dong Y on Mar 06, 2013 11:03 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
Thanks you for posting !
Left by tai nghe bluetooth on Mar 11, 2013 4:54 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
'm looking for this and found this website thanks only will it help me a lot. tks you!
Left by Diem dan rao vat on Mar 11, 2013 4:58 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
'm looking for this and found this website thanks only will it help me a lot. tks you!
Left by Dien dan rao vat on Mar 11, 2013 4:59 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
I found your site is perfect for my needs. It contains wonderful and helpful post. I have read most of them, and learned a lot from them. You do some good work. Thank you for making such a nice website.
Left by may loc nuoc on Apr 18, 2013 9:27 AM

# re: Databinding a .Net WinForms ComboBox to an Enum
Requesting Gravatar...
myself have learned a lot from article, thank you for sharing.
Left by may loc nuoc ro on May 07, 2013 1:16 AM

Your comment:
 (will show your gravatar)


Copyright © Tim Huffam | Powered by: GeeksWithBlogs.net