<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr</title>
<link>http://snipplr.com/language/c-sharp/tags/gui</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Sat, 25 May 2013 16:20:29 GMT</pubDate>
<item>
<title>(C#) Add index numbers to each row header in a DataGridView - pckujawa</title>
<link>http://snipplr.com/view/31065/add-index-numbers-to-each-row-header-in-a-datagridview/</link>
<description><![CDATA[ <p>`w_Dgv` is the name of the DataGridView control.</p> ]]></description>
<pubDate>Wed, 07 Apr 2010 12:15:42 GMT</pubDate>
<guid>http://snipplr.com/view/31065/add-index-numbers-to-each-row-header-in-a-datagridview/</guid>
</item>
<item>
<title>(C#) Persisting values in an application between executions and upgrades (.NET) - pckujawa</title>
<link>http://snipplr.com/view/29302/persisting-values-in-an-application-between-executions-and-upgrades-net/</link>
<description><![CDATA[ <p>Read the [best article on the subject - Exploring Secrets of Persistent Application Settings](http://www.devx.com/dotnet/Article/33944/1954) - and then the following links if desired. (Note, I recommend reading [this forum post about settings not being upgraded](http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/790980e8-eb89-492c-976b-4f93dc7c1caf/).)

It might help to understand [What is app.config for?](http://stackoverflow.com/questions/1431742/what-is-app-config-for)

Also of note: [Saving out a Form's Size and Location using the Application Settings feature](http://blogs.msdn.com/rprabhu/archive/2005/11/28/497792.aspx). Be sure to read the first couple of comments as well.

Lastly, if you are interested in import/export functionality, check out [my post on the subject](http://stackoverflow.com/questions/2389290/how-to-load-a-separate-application-settings-file-dynamically-and-merge-with-curre).</p> ]]></description>
<pubDate>Thu, 04 Mar 2010 17:08:30 GMT</pubDate>
<guid>http://snipplr.com/view/29302/persisting-values-in-an-application-between-executions-and-upgrades-net/</guid>
</item>
<item>
<title>(C#) Hex edit control for .NET GUI - pckujawa</title>
<link>http://snipplr.com/view/28343/hex-edit-control-for-net-gui/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 15 Feb 2010 13:35:13 GMT</pubDate>
<guid>http://snipplr.com/view/28343/hex-edit-control-for-net-gui/</guid>
</item>
<item>
<title>(C#) Binding an enum to a control (such as a ComboBox or DataGridView) with a custom string for each enum value - pckujawa</title>
<link>http://snipplr.com/view/23615/binding-an-enum-to-a-control-such-as-a-combobox-or-datagridview-with-a-custom-string-for-each-enum-value/</link>
<description><![CDATA[ <p>When you want to put the values of an enumeration into a ComboBox or similar control, there is no obvious or easy way to customize the text displayed. 

[UPDATE] The best method I've found is to use a custom TypeConverter. I haven't worked out all the intricacies, but the code below works for combo/listboxes and datagridviews, and I imagine that it would work with all IComponents.

One method below uses the System.ComponentModel.DescriptionAttribute to create a nice description of the enum value and then reads those values using reflection and an extension method (requires .NET 3.5 - see the references for alternatives). Once those values are read, they are put in a Dictionary in order to act as the DataSource for a ComboBox (named w_wifiSecurityIO in the example). 

Unfortunately, attributes (to my knowledge) cannot access resources, so the first method does not allow for localization. To overcome this challenge, I have used a Dictionary as the control's Tag and then use the SelectedItem.ToString as the lookup for the enum value selected (works with multiple selections and Flags enums as well, e.g. in a CheckedListBox). The second method uses a Dictionary for the DataSource, sets the DisplayMember and ValueMember properties, then retrieves using the SelectedValue property.

(Since the initialization code is only called once, and there are only a few enum values, the performance hit for using reflection is negligible. Even if it were noticeable, it might still be warranted when compared to other methods of customizing the displayed text.)

The third method comes from the answer to a [StackOverflow question about the subject](http://stackoverflow.com/questions/1415140/c-enums-can-my-enums-have-friendly-names/1415460#1415460) and uses a simple extension method that allows for localization.

Another method is [enumeration classes](http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/08/12/enumeration-classes.aspx).

(Used in RedBird::Hawk.)

References:
[msmvps.com](http://msmvps.com/blogs/deborahk/archive/2009/07/10/enum-binding-to-the-description-attribute.aspx)
[codeproject](http://www.codeproject.com/KB/cs/enumdatabinding.aspx)
[blogs.msdn](http://blogs.msdn.com/abhinaba/archive/2005/10/21/483337.aspx)
[local ms help](ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system/html/7f153948-1284-313b-1f33-a6ed0d817322.htm) (DescriptionAttribute Class)</p> ]]></description>
<pubDate>Mon, 23 Nov 2009 14:52:51 GMT</pubDate>
<guid>http://snipplr.com/view/23615/binding-an-enum-to-a-control-such-as-a-combobox-or-datagridview-with-a-custom-string-for-each-enum-value/</guid>
</item>
<item>
<title>(C#) Scroll to the bottom of a text box control programmatically - pckujawa</title>
<link>http://snipplr.com/view/9922/scroll-to-the-bottom-of-a-text-box-control-programmatically/</link>
<description><![CDATA[ <p>This technique is useful for when you are displaying text back to the user in a GUI and want the most recent text to be displayed at the bottom of the text control, but you want that information to be visible.

Another nice function that works well if you aren’t moving up and down in the text box is the textbox.AppendText function.  It will add the text to the bottom and keep the textbox from going to the top. (Thanks to Charlie Mann for that one.)</p> ]]></description>
<pubDate>Wed, 19 Nov 2008 12:17:29 GMT</pubDate>
<guid>http://snipplr.com/view/9922/scroll-to-the-bottom-of-a-text-box-control-programmatically/</guid>
</item>
</channel>
</rss>