<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>the jackol's den &#187; C#/.NET</title>
	<atom:link href="http://www.thejackol.com/category/tips/c-sharp-dot-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thejackol.com</link>
	<description>01100010 01101100 01100101 01101000</description>
	<lastBuildDate>Wed, 28 Dec 2011 03:40:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>URL Routing problem with ASP.NET 4 on GoDaddy IIS 7</title>
		<link>http://www.thejackol.com/2011/03/24/url-routing-problem-with-asp-net-4-on-godaddy-iis-7/</link>
		<comments>http://www.thejackol.com/2011/03/24/url-routing-problem-with-asp-net-4-on-godaddy-iis-7/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 20:37:37 +0000</pubDate>
		<dc:creator>Mikhail Esteves</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.thejackol.com/?p=691</guid>
		<description><![CDATA[If you get 404 errors when trying to add URL Routing with ASP.NET 4 (Web Forms) on GoDaddy, simply reference the relevant modules in your web.config file: &#60;modules runAllManagedModulesForAllRequests=&#34;true&#34;&#62; &#60;remove name=&#34;UrlRoutingModule&#34; /&#62; &#60;add name=&#34;UrlRoutingModule&#34; type=&#34;System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&#34; /&#62; &#60;/modules&#62; &#60;handlers&#62; &#60;add name=&#34;UrlRoutingHandler&#34; preCondition=&#34;integratedMode&#34; verb=&#34;*&#34; path=&#34;UrlRouting.axd&#34; type=&#34;System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&#34;/&#62; &#60;/handlers&#62; Add this [...]]]></description>
			<content:encoded><![CDATA[	<p>If you get 404 errors when trying to add <span class="caps">URL</span> Routing with <span class="caps">ASP</span>.<span class="caps">NET</span> 4 (Web Forms) on GoDaddy, simply reference the relevant modules in your web.config file:</p>

<pre><code>    &#60;modules runAllManagedModulesForAllRequests=&#34;true&#34;&#62; 
      &#60;remove name=&#34;UrlRoutingModule&#34; /&#62; 
      &#60;add name=&#34;UrlRoutingModule&#34; type=&#34;System.Web.Routing.UrlRoutingModule, System.Web, 
        Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&#34; /&#62; 
    &#60;/modules&#62; 
    &#60;handlers&#62; 
      &#60;add name=&#34;UrlRoutingHandler&#34; 
        preCondition=&#34;integratedMode&#34; 
        verb=&#34;*&#34; path=&#34;UrlRouting.axd&#34; 
        type=&#34;System.Web.HttpForbiddenHandler, System.Web,  
        Version=2.0.0.0, Culture=neutral,  
        PublicKeyToken=b03f5f7f11d50a3a&#34;/&#62; 
    &#60;/handlers&#62; 
</code></pre>

	<p>
Add this to the system.webServer node.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thejackol.com/2011/03/24/url-routing-problem-with-asp-net-4-on-godaddy-iis-7/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>LINQ to SQL log to debug window, file, memory or multiple writers</title>
		<link>http://www.thejackol.com/2010/08/05/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers/</link>
		<comments>http://www.thejackol.com/2010/08/05/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 13:46:06 +0000</pubDate>
		<dc:creator>Mikhail Esteves</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.thejackol.com/?p=669</guid>
		<description><![CDATA[From here class DebugTextWriter : System.IO.TextWriter { public override void Write(char[] buffer, int index, int count) { System.Diagnostics.Debug.Write(new String(buffer, index, count)); } public override void Write(string value) { System.Diagnostics.Debug.Write(value); } public override Encoding Encoding { get { return System.Text.Encoding.Default; } } }]]></description>
			<content:encoded><![CDATA[	<p>From <a href="http://damieng.com/blog/2008/07/30/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers">here</a></p>

<pre><code>class DebugTextWriter : System.IO.TextWriter {
   public override void Write(char[] buffer, int index, int count) {
       System.Diagnostics.Debug.Write(new String(buffer, index, count));
   }
</code>
<code>   public override void Write(string value) {
       System.Diagnostics.Debug.Write(value);
   }
</code>
<code>   public override Encoding Encoding {
       get { return System.Text.Encoding.Default; }
   }
}
</code></pre>]]></content:encoded>
			<wfw:commentRss>http://www.thejackol.com/2010/08/05/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prevent One Click Attacks by setting ViewStateUserKey in ASP.NET applications</title>
		<link>http://www.thejackol.com/2009/09/14/prevent-one-click-attacks-by-setting-viewstateuserkey-in-asp-net-applications/</link>
		<comments>http://www.thejackol.com/2009/09/14/prevent-one-click-attacks-by-setting-viewstateuserkey-in-asp-net-applications/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 20:11:08 +0000</pubDate>
		<dc:creator>Mikhail Esteves</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.thejackol.com/?p=633</guid>
		<description><![CDATA[Here&#8217;s an easy way to avoid One Click Attacks in ASP.NET applications. If you have a Base class that all your ASP.NET pages derive from, override the OnInit function. For example: protected override void OnInit(EventArgs e) { base.OnInit(e); if (User.Identity.IsAuthenticated) ViewStateUserKey = User.Identity.Name; } If you don&#8217;t have a base class defined, you would have [...]]]></description>
			<content:encoded><![CDATA[	<p>Here&#8217;s an easy way to avoid <a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">One Click Attacks</a> in <span class="caps">ASP</span>.<span class="caps">NET</span> applications. If you have a Base class that all your <span class="caps">ASP</span>.<span class="caps">NET</span> pages derive from, override the <code>OnInit</code> function. For example:</p>

<pre><code>protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
</code>
<code>    if (User.Identity.IsAuthenticated)
        ViewStateUserKey = User.Identity.Name;
}
</code></pre>

	<p>If you don&#8217;t have a base class defined, you would have to put the above code in every <span class="caps">ASP</span>.<span class="caps">NET</span> page.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thejackol.com/2009/09/14/prevent-one-click-attacks-by-setting-viewstateuserkey-in-asp-net-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encrypt your config please&#8230;</title>
		<link>http://www.thejackol.com/2009/07/23/encrypt-your-config-please/</link>
		<comments>http://www.thejackol.com/2009/07/23/encrypt-your-config-please/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 07:34:26 +0000</pubDate>
		<dc:creator>Raghu</dc:creator>
				<category><![CDATA[C#/.NET]]></category>

		<guid isPermaLink="false">http://www.thejackol.com/?p=618</guid>
		<description><![CDATA[ASP.NET 2.0 makes encrypting configSections in the web.config file a snap and there is no reason to not encrypt sensitive configSections. Just google for &#8220;encrypt config&#8221; and there are tons of code snippets waiting for you to copy and paste. Below is a code snippet that is found most commonly in google search results for [...]]]></description>
			<content:encoded><![CDATA[	<p><span class="caps">ASP</span>.<span class="caps">NET</span> 2.0 makes encrypting configSections in the web.config file a snap and there is no reason to not encrypt sensitive configSections. Just google for &#8220;encrypt config&#8221; and there are tons of code snippets waiting for you to copy and paste. Below is a code snippet that is found most commonly in google search results for protecting and unprotecting web.config file:<br />
<pre><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> ProtectSection(</span><span style="color: #0000ff">string</span><span style="color: #000000"> sectionName, </span><span style="color: #0000ff">string</span><span style="color: #000000"> provider)<br />
{
    Configuration config </span><span style="color: #000000">=</span><span style="color: #000000"> WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);</p>

    ConfigurationSection section </span><span style="color: #000000">= </span><span style="color: #000000">config.GetSection(sectionName);

    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (section </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000"> </span><span style="color: #000000">&amp;&amp; </span><span style="color: #000000">!</span><span style="color: #000000">section.SectionInformation.IsProtected)
    {
        section.SectionInformation.ProtectSection(provider);
        config.Save();
    }
}
</span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> UnProtectSection(</span><span style="color: #0000ff">string</span><span style="color: #000000"> sectionName)
{
    Configuration config </span><span style="color: #000000">=</span><span style="color: #000000"> WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

    ConfigurationSection section </span><span style="color: #000000">= </span><span style="color: #000000">config.GetSection(sectionName);

    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (section </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000"> </span><span style="color: #000000">&amp;&amp; </span><span style="color: #000000">section.SectionInformation.IsProtected)
    {
        section.SectionInformation.UnprotectSection();
        config.Save();
    }
}
</span><span style="color: #000000"> </span></pre>
You would usually call <strong>ProtectSection </strong>method in the <strong>Application_Start</strong> event in global.asax. As you can see, it accepts two parameters, sectionName (like &#8220;connectionStrings&#8221;) and provider which is basically an encryption services provider. <span class="caps">ASP</span>.<span class="caps">NET</span> ships with 2 default providers:
<ul>
	<li>The Windows Data Protection <span class="caps">API</span> (<span class="caps">DPAPI</span>) Provider (<strong>DataProtectionConfigurationProvider</strong>)
If you use this provider then the encryption keys are provided by the Windows OS. You don&#8217;t need to maintain the keys. However, this also means that you will need to deploy you application initially with a plain-text config file and then wait for your application logic to actually encrypt it.</li>
</ul>
<ul>
	<li><span class="caps">RSA</span> Protected Configuration Provider (<strong>RSAProtectedConfigurationProvider</strong>)
If you use this options then you are also required to create key containers to hold the public and private keys used for encrypting and decrypting the config information.</li>
</ul>
Once the data is encrypted, you don&#8217;t need to change anything in your code while accessing the settings. The <span class="caps">ASP</span>.<span class="caps">NET</span> configuration classes are smart enough to decrypt and provide you plain-text when they come across encrypted configSections. Pretty cool eh!

	<p>Please note that you may never need to invoke the UnprotectSection method. It is only provided, just in case you want to revert back to a plain-text config file.</p>

	<p>For a complete detailed tutorial on encrypting configSections see <a href="http://aspnet.4guysfromrolla.com/articles/021506-1.aspx" target="_blank">http://aspnet.4guysfromrolla.com/articles/021506-1.aspx</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.thejackol.com/2009/07/23/encrypt-your-config-please/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET AJAX CalendarExtender losing styles</title>
		<link>http://www.thejackol.com/2009/06/23/asp-net-ajax-calendarextender-losing-styles/</link>
		<comments>http://www.thejackol.com/2009/06/23/asp-net-ajax-calendarextender-losing-styles/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 20:01:35 +0000</pubDate>
		<dc:creator>Mikhail Esteves</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.thejackol.com/?p=605</guid>
		<description><![CDATA[If the AJAX CalendarExtender control shows up without any style information or in the wrong places, the simplest solution is to copy the original CSS for the Calendar&#8217;s default style (located at AjaxControlToolkit\Calendar\Calendar.css into your application&#8217;s CSS file. Also make sure the CssClass property is not defined in your CalendarExtender. The actual content of the [...]]]></description>
			<content:encoded><![CDATA[	<p>If the <span class="caps">AJAX</span> CalendarExtender control shows up without any style information or in the wrong places, the simplest solution is to copy the original <span class="caps">CSS</span> for the Calendar&#8217;s default style (located at <code>AjaxControlToolkit\Calendar\Calendar.css</code> into your application&#8217;s <span class="caps">CSS</span> file. Also make sure the <code>CssClass</code> property is not defined in your <code>CalendarExtender</code>. The actual content of the default Calendar style is below:</p>

<pre><code>.ajax__calendar_container {padding:4px;position:absolute;cursor:default;width:170px;
    font-size:11px;text-align:center;font-family:tahoma,verdana,helvetica;}
.ajax__calendar_body {height:139px;width:170px;position:relative;overflow:hidden;
    margin:auto;}
.ajax__calendar_days, .ajax__calendar_months, .ajax__calendar_years {top:0px;left:0px;
    height:139px;width:170px;position:absolute;text-align:center;margin:auto;}
.ajax__calendar_container TABLE {font-size:11px;}
.ajax__calendar_header {height:20px;width:100%;}
.ajax__calendar_prev {cursor:pointer;width:15px;height:15px;float:left;
    background-repeat:no-repeat;background-position:50% 50%;
    background-image:url(&#60; %=WebResource(&#34;AjaxControlToolkit.Calendar.arrow-left.gif&#34;)%&#62;);}
.ajax__calendar_next {cursor:pointer;width:15px;height:15px;float:right;
    background-repeat:no-repeat;background-position:50% 50%;
    background-image:url(&#60; %=WebResource(&#34;AjaxControlToolkit.Calendar.arrow-right.gif&#34;)%&#62;);}
.ajax__calendar_title {cursor:pointer;font-weight:bold;}
.ajax__calendar_footer {height:15px;}
.ajax__calendar_today {cursor:pointer;padding-top:3px;}
.ajax__calendar_dayname {height:17px;width:17px;text-align:right;padding:0 2px;}
.ajax__calendar_day {height:17px;width:18px;text-align:right;padding:0 2px;cursor:pointer;}
.ajax__calendar_month {height:44px;width:40px;text-align:center;cursor:pointer;overflow:hidden;}
.ajax__calendar_year {height:44px;width:40px;text-align:center;cursor:pointer;overflow:hidden;}
</code>
<code>.ajax__calendar .ajax__calendar_container {border:1px solid #646464;background-color:#ffffff;
    color:#000000;}
.ajax__calendar .ajax__calendar_footer {border-top:1px solid #f5f5f5;}
.ajax__calendar .ajax__calendar_dayname {border-bottom:1px solid #f5f5f5;}
.ajax__calendar .ajax__calendar_day {border:1px solid #ffffff;}
.ajax__calendar .ajax__calendar_month {border:1px solid #ffffff;}
.ajax__calendar .ajax__calendar_year {border:1px solid #ffffff;}
</code>
<code>.ajax__calendar .ajax__calendar_active .ajax__calendar_day {background-color:#edf9ff;
    border-color:#0066cc;color:#0066cc;}
.ajax__calendar .ajax__calendar_active .ajax__calendar_month {background-color:#edf9ff;
    border-color:#0066cc;color:#0066cc;}
.ajax__calendar .ajax__calendar_active .ajax__calendar_year {background-color:#edf9ff;
    border-color:#0066cc;color:#0066cc;}
</code>
<code>.ajax__calendar .ajax__calendar_other .ajax__calendar_day {background-color:#ffffff;
    border-color:#ffffff;color:#646464;}
.ajax__calendar .ajax__calendar_other .ajax__calendar_year {background-color:#ffffff;
    border-color:#ffffff;color:#646464;}
</code>
<code>.ajax__calendar .ajax__calendar_hover .ajax__calendar_day {background-color:#edf9ff;
    border-color:#daf2fc;color:#0066cc;}
.ajax__calendar .ajax__calendar_hover .ajax__calendar_month {background-color:#edf9ff;
    border-color:#daf2fc;color:#0066cc;}
.ajax__calendar .ajax__calendar_hover .ajax__calendar_year {background-color:#edf9ff;
    border-color:#daf2fc;color:#0066cc;}
</code>
<code>.ajax__calendar .ajax__calendar_hover .ajax__calendar_title {color:#0066cc;}
.ajax__calendar .ajax__calendar_hover .ajax__calendar_today {color:#0066cc;}
</code></pre>

	<p>#</p>]]></content:encoded>
			<wfw:commentRss>http://www.thejackol.com/2009/06/23/asp-net-ajax-calendarextender-losing-styles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get LINQ to SQL results into a DataTable</title>
		<link>http://www.thejackol.com/2009/06/02/get-linq-to-sql-results-into-a-datatable/</link>
		<comments>http://www.thejackol.com/2009/06/02/get-linq-to-sql-results-into-a-datatable/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 08:33:09 +0000</pubDate>
		<dc:creator>Mikhail Esteves</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[linq to sql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.thejackol.com/?p=594</guid>
		<description><![CDATA[There are two ways to get LINQ to SQL results into a DataTable, as explained here. I use Sample II: public DataTable ToDataTable(System.Data.Linq.DataContext ctx, object query) { if (query == null) { throw new ArgumentNullException(&#34;query&#34;); } IDbCommand cmd = ctx.GetCommand(query as IQueryable); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = (SqlCommand)cmd; DataTable dt = new DataTable(&#34;sd&#34;); [...]]]></description>
			<content:encoded><![CDATA[	<p>There are two ways to get <span class="caps">LINQ</span> to <span class="caps">SQL</span> results into a DataTable, <a href="http://www.c-sharpcorner.com/UploadFile/VIMAL.LAKHERA/LINQResultsetToDatatable06242008042629AM/LINQResultsetToDatatable.aspx" ref="external nofollow">as explained here</a>.</p>

	<p>I use Sample II:</p>

<pre><code>public DataTable ToDataTable(System.Data.Linq.DataContext ctx, object query)
{
     if (query == null)
     {
          throw new ArgumentNullException(&#34;query&#34;);
     }
</code>
<code>     IDbCommand cmd = ctx.GetCommand(query as IQueryable);
     SqlDataAdapter adapter = new SqlDataAdapter();
     adapter.SelectCommand = (SqlCommand)cmd;
     DataTable dt = new DataTable(&#34;sd&#34;);
</code>
<code>     try
     {
          cmd.Connection.Open();
          adapter.FillSchema(dt, SchemaType.Source); 
          adapter.Fill(dt);
     }
     finally
     {
          cmd.Connection.Close();
     }
     return dt;
}
</code></pre>

	<p>//</p>]]></content:encoded>
			<wfw:commentRss>http://www.thejackol.com/2009/06/02/get-linq-to-sql-results-into-a-datatable/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Autostarting your WinForms application</title>
		<link>http://www.thejackol.com/2008/05/25/autostarting-your-winforms-application/</link>
		<comments>http://www.thejackol.com/2008/05/25/autostarting-your-winforms-application/#comments</comments>
		<pubDate>Sun, 25 May 2008 16:45:15 +0000</pubDate>
		<dc:creator>Mikhail Esteves</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.thejackol.com/2008/05/25/autostarting-your-winforms-application/</guid>
		<description><![CDATA[Here&#8217;s a helper function to add your Winforms application to the Windows startup list: public static void AddAutoStartProgram(string name, string appPath) { string runKeyBase = @&#34;Software\Microsoft\Windows\CurrentVersion\Run\&#34;; RegistryKey rk = Registry.CurrentUser .OpenSubKey(runKeyBase + name); if (rk == null) { RegistryKey runKey = Registry.CurrentUser .CreateSubKey(runKeyBase); runKey.SetValue(name, appPath); runKey.Close(); } else { rk.SetValue(name, appPath); rk.Close(); } } Usage [...]]]></description>
			<content:encoded><![CDATA[	<p>Here&#8217;s a helper function to add your Winforms application to the Windows startup list:</p>

<pre><code>public static void AddAutoStartProgram(string name, string appPath)
{
  string runKeyBase = @&#34;Software\Microsoft\Windows\CurrentVersion\Run\&#34;;
  RegistryKey rk = Registry.CurrentUser
    .OpenSubKey(runKeyBase + name);
</code>
<code>  if (rk == null)
  {
    RegistryKey runKey = Registry.CurrentUser
        .CreateSubKey(runKeyBase);
    runKey.SetValue(name, appPath);
    runKey.Close();
  }
  else
  {
    rk.SetValue(name, appPath);
    rk.Close();
  }
}
</code></pre>

	<p><br />
Usage is simple: <code>AddAutoStartProgram(&#34;myapp&#34;, Application.ExecutablePath);</code></p>

	<p>To remove a program from automatically starting up, just delete the key:</p>

<pre><code>public static void RemoveAutoStartProgram(string name)
  {
  string runKeyBase = @&#34;Software\Microsoft\Windows\CurrentVersion\Run&#34;;
</code>
<code>  RegistryKey rk = Registry.CurrentUser.OpenSubKey(runKeyBase, true);
  rk.DeleteValue(name, false);
  rk.Close();
  }
</code></pre>

	<p><br />
Remove your app with a call like <code>RemoveAutoStartProgram(&#34;myapp&#34;);</code></p>]]></content:encoded>
			<wfw:commentRss>http://www.thejackol.com/2008/05/25/autostarting-your-winforms-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WinForms ComboBox with values like the WebForms DropDownList</title>
		<link>http://www.thejackol.com/2008/01/17/winforms-combobox-with-values-like-the-webforms-dropdownlist/</link>
		<comments>http://www.thejackol.com/2008/01/17/winforms-combobox-with-values-like-the-webforms-dropdownlist/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 02:47:40 +0000</pubDate>
		<dc:creator>Mikhail Esteves</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.thejackol.com/2008/01/17/winforms-combobox-with-values-like-the-webforms-dropdownlist/</guid>
		<description><![CDATA[	<p>Want to have values for each ComboBox item in WinForms? Here is a simple way of doing so. Add a class in your project named <code>ComboBoxItem</code>:</p>

<pre><code>public class ComboBoxItem
{
  private string _value;
  private string _text;
</code>
<code>  public string Value { get { return _value; } }
  public string Text  { get { return _text ; } }
</code>
<code>  public ComboBoxItem (string cValue, cText)
  {
    this._value = cValue;
    this._text  = cText;
  }
}
</code></pre>

	<p>Now when adding items to the ComboBox, you would do this:</p>

<pre><code>ComboBox myBox = new ComboBox ();
myBox.Items.Add (new ComboBoxItem (&#34;1&#34;, &#34;January&#34;));
myBox.Items.Add (new ComboBoxItem (&#34;2&#34;, &#34;February&#34;));
</code>
<code>myBox.DisplayMember = &#34;Text&#34;; // Specifies what to display
this.Controls.Add (myBox);
</code></pre>

	<p>To retrieve the current selected value and text, you could do:</p>

<pre><code>string SelectedItemValue = (myBox.SelectedItem as ComboBoxItem).Value;
string SelectedItemText  = (myBox.SelectedItem as ComboBoxItem).Text;
</code></pre>

	<p><form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="WG52GT6V5BL3C">
<table>
<tr><td><input type="hidden" name="on0" value="Options">Options</td></tr><tr><td><select name="os0">
	<option value="Donate">Donate $1.00</option>
	<option value="Donate">Donate $5.00</option>
	<option value="Donate">Donate $10.00</option>
	<option value="Donate">Donate $50.00</option>
	<option value="Donate">Donate $100.00</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form></p>]]></description>
			<content:encoded><![CDATA[	<p>Want to have values for each ComboBox item in WinForms? Here is a simple way of doing so. Add a class in your project named <code>ComboBoxItem</code>:</p>

<pre><code>public class ComboBoxItem
{
  private string _value;
  private string _text;
</code>
<code>  public string Value { get { return _value; } }
  public string Text  { get { return _text ; } }
</code>
<code>  public ComboBoxItem (string cValue, cText)
  {
    this._value = cValue;
    this._text  = cText;
  }
}
</code></pre>

	<p>Now when adding items to the ComboBox, you would do this:</p>

<pre><code>ComboBox myBox = new ComboBox ();
myBox.Items.Add (new ComboBoxItem (&#34;1&#34;, &#34;January&#34;));
myBox.Items.Add (new ComboBoxItem (&#34;2&#34;, &#34;February&#34;));
</code>
<code>myBox.DisplayMember = &#34;Text&#34;; // Specifies what to display
this.Controls.Add (myBox);
</code></pre>

	<p>To retrieve the current selected value and text, you could do:</p>

<pre><code>string SelectedItemValue = (myBox.SelectedItem as ComboBoxItem).Value;
string SelectedItemText  = (myBox.SelectedItem as ComboBoxItem).Text;
</code></pre>

	<p><form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="WG52GT6V5BL3C">
<table>
<tr><td><input type="hidden" name="on0" value="Options">Options</td></tr><tr><td><select name="os0">
	<option value="Donate">Donate $1.00</option>
	<option value="Donate">Donate $5.00</option>
	<option value="Donate">Donate $10.00</option>
	<option value="Donate">Donate $50.00</option>
	<option value="Donate">Donate $100.00</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form></p>]]></content:encoded>
			<wfw:commentRss>http://www.thejackol.com/2008/01/17/winforms-combobox-with-values-like-the-webforms-dropdownlist/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

