<?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>dotnet thoughts &#187; Windows Forms</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/windows-forms/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>a dotnet developer&#039;s technical blog</description>
	<lastBuildDate>Thu, 02 Feb 2012 03:18:00 +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>How to debug Windows Live Writer plugins</title>
		<link>http://www.dotnetthoughts.net/2011/11/20/how-to-debug-windows-live-writer-plugins/</link>
		<comments>http://www.dotnetthoughts.net/2011/11/20/how-to-debug-windows-live-writer-plugins/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 09:29:07 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Live Writer Plugin]]></category>
		<category><![CDATA[Windows Live Writer]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2042</guid>
		<description><![CDATA[This is final post related to live writer plugins and its about debugging the Live writer plugins. While developing I don&#8217;t think there is a way we can debug the plugin code. This is after deployment. Initially I faced one &#8230; <a href="http://www.dotnetthoughts.net/2011/11/20/how-to-debug-windows-live-writer-plugins/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">This is final post related to live writer plugins and its about debugging the Live writer plugins. While developing I don&#8217;t think there is a way we can debug the plugin code. This is after deployment. Initially I faced one issue with options dialog, it was related to object reference issue, I got a message like this.</p>
<div id="attachment_2044" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/plugin_settings_error.jpg"><img class="size-medium wp-image-2044" title="Plug-in Error occured - Messagebox from Windows Live Writer" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/plugin_settings_error-300x197.jpg" alt="Plug-in Error occured - Messagebox from Windows Live Writer" width="300" height="197" /></a><p class="wp-caption-text">Plug-in Error occured - Messagebox from Windows Live Writer</p></div>
<p style="text-align: justify;">It only shows the exception message, not the stack trace or any other information which helps to find the exception. For debugging, you need to attach the Windows Live writer to Visual Studio(we may need to run visual studio as Administrator) using Attach Process feature of Visual Studio from Debug menu.</p>
<div id="attachment_2043" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/attachprocess.jpg"><img class="size-medium wp-image-2043" title="Attach Windows Live Writer to Visual Studio" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/attachprocess-300x190.jpg" alt="Attach Windows Live Writer to Visual Studio" width="300" height="190" /></a><p class="wp-caption-text">Attach Windows Live Writer to Visual Studio</p></div>
<p>Happy Programming.</p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2011/11/16/how-to-create-a-windows-live-writer-plugin-using-c-part-1/" title="Permanent link to How to create a Windows Live writer plugin using C# Part 1">How to create a Windows Live writer plugin using C# Part 1</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/11/19/how-to-create-a-windows-live-writer-plugin-using-c-part-2/" title="Permanent link to How to create a Windows Live writer plugin using C# Part 2">How to create a Windows Live writer plugin using C# Part 2</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/08/03/windows-7-sdk-installation-success-or-error-status-1603/" title="Permanent link to Windows 7 SDK Installation success or error status: 1603">Windows 7 SDK Installation success or error status: 1603</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/06/02/how-to-integrate-fxcop-to-visual-studio-2010-professional/" title="Permanent link to How to integrate FxCop to Visual Studio 2010 Professional">How to integrate FxCop to Visual Studio 2010 Professional</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/06/18/debugging-windows-services/" title="Permanent link to Debugging Windows Services">Debugging Windows Services</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2011/11/20/how-to-debug-windows-live-writer-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create a Windows Live writer plugin using C# Part 2</title>
		<link>http://www.dotnetthoughts.net/2011/11/19/how-to-create-a-windows-live-writer-plugin-using-c-part-2/</link>
		<comments>http://www.dotnetthoughts.net/2011/11/19/how-to-create-a-windows-live-writer-plugin-using-c-part-2/#comments</comments>
		<pubDate>Sat, 19 Nov 2011 18:43:12 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Link Shortner]]></category>
		<category><![CDATA[Live Writer Plugin]]></category>
		<category><![CDATA[Windows Live Writer]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2030</guid>
		<description><![CDATA[This is the second part of live writer plugin post, in this post I am implementing settings for the live writer plugin. First post I was about creating basic Live writer which help to short link using bit.ly shortening service. &#8230; <a href="http://www.dotnetthoughts.net/2011/11/19/how-to-create-a-windows-live-writer-plugin-using-c-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is the second part of live writer plugin post, in this post I am implementing settings for the live writer plugin. <a href="http://www.dotnetthoughts.net/2011/11/16/how-to-create-a-windows-live-writer-plugin-using-c-part-1/" title="How to create a Windows Live writer plugin using C# Part 1">First post</a> I was about creating basic Live writer which help to short link using bit.ly shortening service. Now I am adding a few more link shortening services like tiny.cc and tinyurl. Also I am providing an option which helps to decide whether the link should open in a new Window or not, or more precisely adding a target=&#8221;blank&#8221; attribute to the inserted anchor tag.</p>
<p>First we need to inform Live Writer that the plugin has settings, which can be done using HasEditableOptions=true in plugin attributes. Now we will create the settings form, which will be like the following.</p>
<div id="attachment_2032" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/settings_design_view.jpg"><img class="size-medium wp-image-2032" title="Plugin settings - Design View" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/settings_design_view-300x135.jpg" alt="Plugin settings - Design View" width="300" height="135" /></a><p class="wp-caption-text">Plugin settings - Design View</p></div>
<p>Live writer will invoke the EditOptions method in the Plugin class for displaying the settings, so we need to override the method for displaying the form.</p>
<pre class="brush: csharp; title: ; notranslate">
public override void EditOptions(IWin32Window dialogOwner)
{
    Settings settings = new Settings(_pluginSettings);
    settings.ShowDialog();
}
</pre>
<p>For implementing plugin settings we can use IProperties, which helps plugin to read/write the settings. The Live writer understands the basic types, like string, int, float, bool and decimal. IProperties exposes methods to get and set the values. Like this</p>
<pre class="brush: csharp; title: ; notranslate">
private IProperties _properties;
public bool UseBlank
{
    get
    {
        return _properties.GetBoolean(&quot;UseBlank&quot;, true);
    }
    set
    {
        _properties.SetBoolean(&quot;UseBlank&quot;, value);
    }
}
</pre>
<p>To save and retrieve the setting the following methods of IProperties class can be used.</p>
<pre class="brush: csharp; title: ; notranslate">
private PluginSettings _settings;
private void cmdSave_Click(object sender, EventArgs e)
{
	_settings.UseBlank = chkBlankTarget.Checked;
	_settings.Provider = ddlProvider.SelectedItem.ToString();
	Close();
}
//Constructor of the Settings Form.
public Settings(PluginSettings settings)
{
    InitializeComponent();
    _settings = settings;
    chkBlankTarget.Checked = _settings.UseBlank;
	ddlProvider.SelectedItem = _settings.Provider;
}
</pre>
<p>For accessing settings in the Plugin, we need to override the Initialize() method of the Plugin class, which takes the IProperties as parameter, LiveWriter will invoke the plugin with the settings.</p>
<pre class="brush: csharp; title: ; notranslate">
private PluginSettings _pluginSettings;
public override void Initialize(IProperties pluginOptions)
{
    base.Initialize(pluginOptions);
    _pluginSettings = new PluginSettings(pluginOptions);
}
</pre>
<p>Build the project, launch the Windows Live Writer, click on the Plugin options, which will show the Plugin options dialog.</p>
<div id="attachment_2031" class="wp-caption aligncenter" style="width: 282px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/plugin_options.jpg"><img class="size-medium wp-image-2031" title="Live Writer - Plugin Options" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/plugin_options-272x300.jpg" alt="Live Writer - Plugin Options" width="272" height="300" /></a><p class="wp-caption-text">Live Writer - Plugin Options</p></div>
<p>Next select Link shortener plugin and click on Options button, which will display the plugin settings dialog we designed.</p>
<div id="attachment_2033" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/shortner_settings.jpg"><img class="size-medium wp-image-2033" title="Live writer Plugin - Settings" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/shortner_settings-300x133.jpg" alt="Live writer Plugin - Settings" width="300" height="133" /></a><p class="wp-caption-text">Live writer Plugin - Settings</p></div>
<p>Change the settings and Save the changes, try run the plugin and verify the results.</p>
<p>Happy Programming. Next post will be about debugging Live writer plugin.</p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2011/11/16/how-to-create-a-windows-live-writer-plugin-using-c-part-1/" title="Permanent link to How to create a Windows Live writer plugin using C# Part 1">How to create a Windows Live writer plugin using C# Part 1</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/11/20/how-to-debug-windows-live-writer-plugins/" title="Permanent link to How to debug Windows Live Writer plugins">How to debug Windows Live Writer plugins</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2008/06/04/ghost-doc-document-this/" title="Permanent link to GhostDoc &#8211; Document this">GhostDoc &#8211; Document this</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/10/29/test-impact-analysis-in-visual-studio-2010/" title="Permanent link to Test impact analysis in Visual Studio 2010">Test impact analysis in Visual Studio 2010</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/10/05/developing-a-single-instance-application-in-c/" title="Permanent link to Developing a Single Instance Application in C#">Developing a Single Instance Application in C#</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2011/11/19/how-to-create-a-windows-live-writer-plugin-using-c-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create a Windows Live writer plugin using C# Part 1</title>
		<link>http://www.dotnetthoughts.net/2011/11/16/how-to-create-a-windows-live-writer-plugin-using-c-part-1/</link>
		<comments>http://www.dotnetthoughts.net/2011/11/16/how-to-create-a-windows-live-writer-plugin-using-c-part-1/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 17:16:56 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Link Shortner]]></category>
		<category><![CDATA[Live Writer Plugin]]></category>
		<category><![CDATA[Windows Live Writer]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=1991</guid>
		<description><![CDATA[Recently I got chance to explore Windows Live Writer. So I thought I will create few posts around Live Writer plugins. In this post I am covering the basics of creating Live Writer plugin. I found various plugins which helps &#8230; <a href="http://www.dotnetthoughts.net/2011/11/16/how-to-create-a-windows-live-writer-plugin-using-c-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Recently I got chance to explore Windows Live Writer. So I thought I will create few posts around Live Writer plugins. In this post I am covering the basics of creating Live Writer plugin. I found various plugins which helps to insert syntax highlighting code in wordpress. So I thought I will create one different, this plugin helps to insert a shorten link using bit.ly site.</p>
<p style="text-align: justify;">So first create a class library, make sure you are selecting the target framework as .Net 2.0, otherwise it may not work. The add refernce of Live Writer API(WindowsLive.Writer.Api.dll), which will be available in C:\Program Files (x86)\Windows Live\Writer. Inherit from ContentSource class or SmartContentSource class. In this post I am using ContentSource class, both of them can be used to create the Plugin. Override the CreateContent method, this method will be invoked when users click on the Plugin in LiveWriter. Create a Windows Form, with one textbox and two buttons.</p>
<div id="attachment_1993" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/dotnetthoughts_1.png"><img class="size-medium wp-image-1993" title="Link shortner - Windows Form Design View" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/dotnetthoughts_1-300x95.png" alt="Link shortner - Windows Form Design View" width="300" height="95" /></a><p class="wp-caption-text">Link shortner - Windows Form Design View</p></div>
<p>And add following attributes to the plugin class which helps live writer to identify the Plugin properties.</p>
<pre class="brush: csharp; title: ; notranslate">
[InsertableContentSource(&quot;Link shortner&quot;)]
[WriterPlugin(&quot;9E560094-F1BA-433D-9FB7-4DEA9A4C3F2F&quot;,
	&quot;Link shortner&quot;,
	PublisherUrl = &quot;www.dotnetthoughts.net&quot;,
	Description = &quot;Helps to insert shorten links.&quot;,
	HasEditableOptions = false,
	ImagePath = &quot;wlwicon.png&quot;)]
public class LinkShortner : ContentSource
{
}
</pre>
<p style="text-align: justify;">HasEditableOptions parameter, helps to provide settings for the live writer plugin. And the ImagePath parameter helps to provide Icon for the plugin. The size should be 16&#215;16. And it should added and Build action should be Embedded Resource.</p>
<p>And here is the overriden CreateContent() method.</p>
<pre class="brush: csharp; title: ; notranslate">
public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
{
    using (Editor editor = new Editor())
    {
        editor.StartPosition = FormStartPosition.CenterParent;
        DialogResult result = editor.ShowDialog(dialogOwner);
        if (result == DialogResult.OK)
        {
			//This function will convert long
			//url to short url using bit.ly REST API.
			//Editor.Url property returns the
			//text of the textbox control.
			string resultUrl = CreateShortUrl(editor.Url);
			string url = string.Format
				(&quot;&lt;a href=&quot;\&quot;http://{0}/\&quot;&quot;&gt;{0}&lt;/a&gt;&quot;, resultUrl);
            content = url;
        }
        return result;
    }
}
</pre>
<p style="text-align: justify;">Thats it. We are done with the creation of live writer plugin. Now the next part is deployment. Change the project output path to C:\Program Files (x86)\Windows Live\Writer\Plugins location, you may need to run Visual Studio as Administrator. Now launch the Windows Live Writer, you can see the plugin loaded <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<div id="attachment_1994" class="wp-caption aligncenter" style="width: 248px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/dotnetthoughts_2.png"><img class="size-full wp-image-1994" title="Link Shortner - Windows Live Writer Plugin" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/dotnetthoughts_2.png" alt="Link Shortner - Windows Live Writer Plugin" width="238" height="94" /></a><p class="wp-caption-text">Link Shortner - Windows Live Writer Plugin</p></div>
<p>Clicking on it will popup the Windows form, with textbox, and clicking on Shorten button will insert a link on the post.</p>
<div id="attachment_1995" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/dotnetthoughts_3.png"><img class="size-medium wp-image-1995" title="Link shortner in Windows Live writer - Running" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/dotnetthoughts_3-300x86.png" alt="Link shortner in Windows Live writer - Running" width="300" height="86" /></a><p class="wp-caption-text">Link shortner in Windows Live writer - Running</p></div>
<p>Next part I will post about how to create settings for plugin. Happy Blogging <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2011/11/19/how-to-create-a-windows-live-writer-plugin-using-c-part-2/" title="Permanent link to How to create a Windows Live writer plugin using C# Part 2">How to create a Windows Live writer plugin using C# Part 2</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/11/20/how-to-debug-windows-live-writer-plugins/" title="Permanent link to How to debug Windows Live Writer plugins">How to debug Windows Live Writer plugins</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/10/11/silverlight-in-sharepoint-wss-3-0/" title="Permanent link to Silverlight in Sharepoint (WSS 3.0)">Silverlight in Sharepoint (WSS 3.0)</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/10/09/creating-a-webpart-using-visual-web-developer-express/" title="Permanent link to Creating a WebPart using Visual Web Developer Express">Creating a WebPart using Visual Web Developer Express</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/09/01/create-uac-compatible-applications-in-net/" title="Permanent link to Create UAC Compatible applications in .NET">Create UAC Compatible applications in .NET</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2011/11/16/how-to-create-a-windows-live-writer-plugin-using-c-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How redirect output from a console application</title>
		<link>http://www.dotnetthoughts.net/2011/11/12/how-redirect-output-from-a-console-application/</link>
		<comments>http://www.dotnetthoughts.net/2011/11/12/how-redirect-output-from-a-console-application/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 10:46:28 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Commandline]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=1969</guid>
		<description><![CDATA[GUI tools are offers better User experience than command line tools. But in few scenarios we don’t require GUI, like MS Build tasks, and in some cases the application may not have a UI, example: ImageMagik tools. If check codeplex.com, &#8230; <a href="http://www.dotnetthoughts.net/2011/11/12/how-redirect-output-from-a-console-application/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">GUI tools are offers better User experience than command line tools. But in few scenarios we don’t require GUI, like MS Build tasks, and in some cases the application may not have a UI, example: ImageMagik tools. If check codeplex.com, you can find n number of applications, which doesn&#8217;t have a UI.</p>
<p style="text-align: justify;">The process class supports redirection of output, error and input to streams instead of normal console output stream. Process class also supports events, which will be raised on error or output data received.</p>
<p style="text-align: justify;">And here is the implementation, which invokes the regasm.exe in .Net Framework location, and executes regasm.exe without any command line argument, which will write the help text to the Text box.</p>
<pre class="brush: csharp; title: ; notranslate">
string app = @&quot;C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe&quot;;
Process process = Process.Start(app);

process.EnableRaisingEvents = true;
process.OutputDataReceived += (o, dre) =&gt;
{
    //To avoid cross thread exceptions.
    if (txtOutput.InvokeRequired)
    {
        this.txtOutput.BeginInvoke((Action)
            delegate { this.txtOutput.Text += dre.Data + Environment.NewLine; });
    }
    else
    {
        this.txtOutput.Text += dre.Data + Environment.NewLine;
    }
};
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.UseShellExecute = false;
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
</pre>
<p style="text-align: justify;">The external tools option in Visual Studio works in similar fashion. You can use this technique for creating user interface for command line tools you use frequently.</p>
<p>Happy coding <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2010/12/25/setting-an-application-on-top-other-windows-using-c/" title="Permanent link to Setting an application on top other windows using C#">Setting an application on top other windows using C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/12/10/process-start-and-directory-setcurrentdirectory/" title="Permanent link to Process.Start() and Directory.SetCurrentDirectory()">Process.Start() and Directory.SetCurrentDirectory()</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/11/25/raven-db-introduction/" title="Permanent link to Raven DB &#8211; Introduction">Raven DB &#8211; Introduction</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2012/01/11/how-to-use-net-assembly-in-vbscript/" title="Permanent link to How to use .Net assembly in VBScript">How to use .Net assembly in VBScript</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/10/05/developing-a-single-instance-application-in-c/" title="Permanent link to Developing a Single Instance Application in C#">Developing a Single Instance Application in C#</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2011/11/12/how-redirect-output-from-a-console-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sortable Binding List for custom data objects</title>
		<link>http://www.dotnetthoughts.net/2011/11/04/sortable-binding-list-for-custom-data-objects/</link>
		<comments>http://www.dotnetthoughts.net/2011/11/04/sortable-binding-list-for-custom-data-objects/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 19:18:20 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[BindingList]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Databinding]]></category>
		<category><![CDATA[Generic list]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=1958</guid>
		<description><![CDATA[Binding generic collections to Windows forms Data gridview can be done using DataSource property of Gridview control. But the problem with normal generic lists that it doesn&#8217;t support sorting, by clicking the grid view headers. .Net Framework provides an generic &#8230; <a href="http://www.dotnetthoughts.net/2011/11/04/sortable-binding-list-for-custom-data-objects/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Binding generic collections to Windows forms Data gridview can be done using DataSource property of Gridview control. But the problem with normal generic lists that it doesn&#8217;t support sorting, by clicking the grid view headers. .Net Framework provides an generic abstract class, <a href="http://msdn.microsoft.com/en-us/library/ms132679.aspx" target="_blank">BindingList&lt;T&gt;</a>, which supports virtual methods for Searching and Sorting <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  And here is an implementation, which will helps to sort a gridview control.</p>
<pre class="brush: plain; title: ; notranslate">
public class SortableList : BindingList
{
    protected override bool SupportsSortingCore
    {
        get
        {
            return true;
        }
    }

    protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
    {
        var sortProperty = prop;
        var sortDirection = direction;

        var list = Items as List;
        list.Sort((T item1, T item2) =&gt;
        {
            var item1Value = item1 == null ? null : sortProperty.GetValue(item1);
            var item2Value = item2 == null ? null : sortProperty.GetValue(item2);
            int result;
            if (item1Value == null)
            {
                result = -1;
            }
            else if (item2Value == null)
            {
                result = 1;
            }
            else
            {
                result = Comparer.Default.Compare(item1Value, item2Value);
            }
            if (sortDirection == ListSortDirection.Descending)
            {
                result = -result;
            }
            return result;
        });
    }
}
</pre>
<p>This post I wrote long back and it was in draft mode, and today I thought of publishing it <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Happy Coding <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2010/12/26/how-to-return-null-from-a-generic-method/" title="Permanent link to How to return null from a generic method">How to return null from a generic method</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/08/09/creating-wizard-using-windows-forms/" title="Permanent link to Creating Wizard using Windows Forms">Creating Wizard using Windows Forms</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/07/03/image-cropping-control-in-c-for-windows-forms/" title="Permanent link to Image cropping control in C# for Windows Forms">Image cropping control in C# for Windows Forms</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/07/02/fluent-email-library-for-c-using-dynamicobject/" title="Permanent link to Fluent email library for c# using DynamicObject">Fluent email library for c# using DynamicObject</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/03/03/update-multiple-elements-at-once-using-linq/" title="Permanent link to Update multiple elements at once using LINQ">Update multiple elements at once using LINQ</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2011/11/04/sortable-binding-list-for-custom-data-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

