<?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>Solomon &#187; C#</title>
	<atom:link href="http://www.ms.oyangudi.com/blog/category/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ms.oyangudi.com/blog</link>
	<description>from Oyangudi...</description>
	<lastBuildDate>Sat, 21 Aug 2010 11:35:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>DateTimePicker &#8211; reset focus</title>
		<link>http://www.ms.oyangudi.com/blog/csharp/datetimepicker-reset-focus/</link>
		<comments>http://www.ms.oyangudi.com/blog/csharp/datetimepicker-reset-focus/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 03:54:18 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[DatTimePicker reset focus]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/vbnet/datetimepicker-reset-focus/</guid>
		<description><![CDATA[Code Snippet &#8211; C# private void dateTimePicker1_Enter(object sender, EventArgs e) { DateTimePickerFormat fmt = dateTimePicker1.Format; dateTimePicker1.Format = DateTimePickerFormat.Long; dateTimePicker1.Format = DateTimePickerFormat.Custom; dateTimePicker1.Format = fmt; } Code Snippet - VB.NET Private Sub DateTimePicker1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.Enter Dim fmt As DateTimePickerFormat = DateTimePicker1.Format DateTimePicker1.Format = DateTimePickerFormat.Long DateTimePicker1.Format = DateTimePickerFormat.Custom DateTimePicker1.Format = [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Code Snippet &#8211; C#</strong></p>
<pre class="brush: csharp;">
        private void dateTimePicker1_Enter(object sender, EventArgs e)
        {
            DateTimePickerFormat fmt = dateTimePicker1.Format;

            dateTimePicker1.Format = DateTimePickerFormat.Long;
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            dateTimePicker1.Format = fmt;
        }
</pre>
</pre>
<p><strong>Code Snippet - VB.NET</strong></p>
<pre class="brush: vb;">

    Private Sub DateTimePicker1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.Enter
        Dim fmt As DateTimePickerFormat = DateTimePicker1.Format

        DateTimePicker1.Format = DateTimePickerFormat.Long
        DateTimePicker1.Format = DateTimePickerFormat.Custom
        DateTimePicker1.Format = fmt
    End Sub
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/csharp/datetimepicker-reset-focus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inherit DataGridView in Windows Forms</title>
		<link>http://www.ms.oyangudi.com/blog/csharp/inherit-datagridview-in-windows-forms/</link>
		<comments>http://www.ms.oyangudi.com/blog/csharp/inherit-datagridview-in-windows-forms/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 17:58:16 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[DataGridView Inheritance]]></category>
		<category><![CDATA[DataGridView Visual Inheritance]]></category>
		<category><![CDATA[DataGridView Windows Forms Inheritance]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/?p=50</guid>
		<description><![CDATA[Create a user control class DataGridViewEx and paste the code snippet given. You can use this control where you want an inherited DataGridView. Download source code &#38; sample: 7z file &#8211; DataGridViewInheritance.7z Zip file &#8211; DataGridViewInheritance.zip using System; using System.ComponentModel; using System.Design; using System.Drawing; using System.Windows.Forms; namespace DataGridViewInheritance { [Designer(typeof(System.Windows.Forms.Design.ControlDesigner))] public partial class DataGridViewEx : [...]]]></description>
			<content:encoded><![CDATA[<p>Create a user control class <strong>DataGridViewEx</strong> and paste the code snippet given. You can use this control where you want an inherited DataGridView.</p>
<p><strong>Download source code &amp; sample:</strong></p>
<div id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:09ad80b9-f642-4d4c-aeae-f54682d2b923" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<p>7z file &#8211; <a href="http://www.ms.oyangudi.com/blog/wp-content/uploads/InheritDataGridViewinWindowsForms_89D6/DataGridViewInheritance.7z">DataGridViewInheritance.7z</a></p>
</div>
<div id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:dc1dcf2a-6534-4aa1-9496-06a4730efa1e" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<p>Zip file &#8211; <a href="http://www.ms.oyangudi.com/blog/wp-content/uploads/InheritDataGridViewinWindowsForms_89D6/DataGridViewInheritance.zip">DataGridViewInheritance.zip</a></p>
</div>
<pre class="brush: csharp;">

using System;
using System.ComponentModel;
using System.Design;
using System.Drawing;
using System.Windows.Forms;

namespace DataGridViewInheritance
{

    [Designer(typeof(System.Windows.Forms.Design.ControlDesigner))]
    public partial class DataGridViewEx : DataGridView
    {
        public DataGridViewEx()
        {
            InitializeComponent();
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/csharp/inherit-datagridview-in-windows-forms/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Decimal to Byte array (vice versa)</title>
		<link>http://www.ms.oyangudi.com/blog/csharp/decimal-to-byte-array/</link>
		<comments>http://www.ms.oyangudi.com/blog/csharp/decimal-to-byte-array/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 04:13:44 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Decimal to Byte array (vice versa)]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/?p=35</guid>
		<description><![CDATA[/// &#60;summary&#62; /// Decimal to Bye array /// &#60;/summary&#62; /// &#60;param name=&#34;dec&#34;&#62;decimal&#60;/param&#62; /// &#60;returns&#62;byte array&#60;/returns&#62; public static byte[] DecimalToBytes(Decimal dec) { using (MemoryStream stream = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(dec); return stream.ToArray(); } } } /// &#60;summary&#62; /// Byte array to Decimal /// &#60;/summary&#62; /// &#60;param name=&#34;src&#34;&#62;byte array&#60;/param&#62; /// [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: csharp;">

        /// &lt;summary&gt;
        /// Decimal to Bye array
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;dec&quot;&gt;decimal&lt;/param&gt;
        /// &lt;returns&gt;byte array&lt;/returns&gt;
        public static byte[] DecimalToBytes(Decimal dec)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    writer.Write(dec);

                    return stream.ToArray();
                }
            }
        }

        /// &lt;summary&gt;
        /// Byte array to Decimal
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;src&quot;&gt;byte array&lt;/param&gt;
        /// &lt;returns&gt;decimal&lt;/returns&gt;
        public static Decimal BytesToDecimal(byte[] src)
        {
            if (src.Length == 1)
            {
                return Decimal.Parse(((char)src[0]).ToString());
            }

           using (MemoryStream stream = new MemoryStream(src))
           {
               using (BinaryReader reader = new BinaryReader(stream))
               {
                   return reader.ReadDecimal();
               }

           }
        }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/csharp/decimal-to-byte-array/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Byte array to String (vice versa)</title>
		<link>http://www.ms.oyangudi.com/blog/csharp/byte-array-to-string-vice-versa/</link>
		<comments>http://www.ms.oyangudi.com/blog/csharp/byte-array-to-string-vice-versa/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 04:03:16 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Byte array to String (vice versa)]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/?p=34</guid>
		<description><![CDATA[/// &#60;summary&#62; /// Byte arrary to String /// &#60;/summary&#62; /// &#60;param name=&#34;bytes&#34;&#62;byte array&#60;/param&#62; /// &#60;returns&#62;string&#60;/returns&#62; public static string BytesToString(byte[] bytes) { ASCIIEncoding enc = new System.Text.ASCIIEncoding(); return enc.GetString(bytes); } /// &#60;summary&#62; /// String to Byte array /// &#60;/summary&#62; /// &#60;param name=&#34;str&#34;&#62;string&#60;/param&#62; /// &#60;returns&#62;byte array&#60;/returns&#62; public static byte[] StringToBytes(string str) { ASCIIEncoding enc = new System.Text.ASCIIEncoding(); [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: csharp;">

        /// &lt;summary&gt;
        /// Byte arrary to String
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;bytes&quot;&gt;byte array&lt;/param&gt;
        /// &lt;returns&gt;string&lt;/returns&gt;
        public static string BytesToString(byte[] bytes)
        {
            ASCIIEncoding enc = new System.Text.ASCIIEncoding();

            return enc.GetString(bytes);
        }

        /// &lt;summary&gt;
        /// String to Byte array
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;str&quot;&gt;string&lt;/param&gt;
        /// &lt;returns&gt;byte array&lt;/returns&gt;
        public static byte[] StringToBytes(string str)
        {
            ASCIIEncoding enc = new System.Text.ASCIIEncoding();

            return enc.GetBytes(str);
        }    
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/csharp/byte-array-to-string-vice-versa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Byte array to Integer (vice versa)</title>
		<link>http://www.ms.oyangudi.com/blog/csharp/byte-array-to-integer-vice-versa/</link>
		<comments>http://www.ms.oyangudi.com/blog/csharp/byte-array-to-integer-vice-versa/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 03:59:18 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Byte array to Integer (vice versa)]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/?p=33</guid>
		<description><![CDATA[/// &#60;summary&#62; /// Byte array to Integer /// &#60;/summary&#62; /// &#60;param name=&#34;bytes&#34;&#62;byte array&#60;/param&#62; /// &#60;returns&#62;int&#60;/returns&#62; public static int BytesToInt(byte[] bytes) { return int.Parse(BytesToString(bytes).Trim()); } /// &#60;summary&#62; /// Byte array to String /// &#60;/summary&#62; /// &#60;param name=&#34;bytes&#34;&#62;byte array&#60;/param&#62; /// &#60;returns&#62;string&#60;/returns&#62; public static string BytesToString(byte[] bytes) { ASCIIEncoding enc = new System.Text.ASCIIEncoding(); return enc.GetString(bytes); } /// &#60;summary&#62; [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: csharp;">

        /// &lt;summary&gt;
        /// Byte array to Integer
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;bytes&quot;&gt;byte array&lt;/param&gt;
        /// &lt;returns&gt;int&lt;/returns&gt;
        public static int BytesToInt(byte[] bytes)
        {
            return int.Parse(BytesToString(bytes).Trim());
        }

        /// &lt;summary&gt;
        /// Byte array to String
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;bytes&quot;&gt;byte array&lt;/param&gt;
        /// &lt;returns&gt;string&lt;/returns&gt;
        public static string BytesToString(byte[] bytes)
        {
            ASCIIEncoding enc = new System.Text.ASCIIEncoding();

            return enc.GetString(bytes);
        }

        /// &lt;summary&gt;
        /// Integer to Byte array
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;value&quot;&gt;int&lt;/param&gt;
        /// &lt;returns&gt;byte array&lt;/returns&gt;
        public static byte[] IntToBytes(int value)
        {
            ASCIIEncoding enc = new System.Text.ASCIIEncoding();

            return enc.GetBytes(value.ToString());
        }

        /// &lt;summary&gt;
        /// Bytes to Integer
        /// &lt;/summary&gt;
        /// &lt;param name=”src”&gt;&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static int BytesToInt(byte[] src)
        {
             if (src.Length == 1)
                 return (int)src[0];
             else if (src.Length &lt;= 2)
                 return BitConverter.ToInt16(src, 0);

             return BitConverter.ToInt32(src, 0);
         }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/csharp/byte-array-to-integer-vice-versa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hexadecimal to Integer (vice versa)</title>
		<link>http://www.ms.oyangudi.com/blog/csharp/hexadecimal-to-decimal-vice-versa/</link>
		<comments>http://www.ms.oyangudi.com/blog/csharp/hexadecimal-to-decimal-vice-versa/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 03:54:36 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Hexadecimal to Integer (vice versa)]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/?p=32</guid>
		<description><![CDATA[/// &#60;summary&#62; /// Hexa decimal to String /// &#60;/summary&#62; /// &#60;param name=&#34;HexString&#34;&#62;hexa decimal string&#60;/param&#62; /// &#60;returns&#62;int&#60;/returns&#62; public static int HexToInteger(string HexString) { return int.Parse(HexString, System.Globalization.NumberStyles.HexNumber); } /// &#60;summary&#62; /// Integer to Hexa decimal string /// &#60;/summary&#62; /// &#60;param name=&#34;IntValue&#34;&#62;int&#60;/param&#62; /// &#60;returns&#62;hexa decimal string&#60;/returns&#62; public static string IntegerToHex(int IntValue) { return IntValue.ToString(&#34;X&#34;); }]]></description>
			<content:encoded><![CDATA[<pre class="brush: csharp;">

        /// &lt;summary&gt;
        /// Hexa decimal to String
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;HexString&quot;&gt;hexa decimal string&lt;/param&gt;
        /// &lt;returns&gt;int&lt;/returns&gt;
        public static int HexToInteger(string HexString)
        {
            return int.Parse(HexString, System.Globalization.NumberStyles.HexNumber);
        }

        /// &lt;summary&gt;
        /// Integer to Hexa decimal string
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;IntValue&quot;&gt;int&lt;/param&gt;
        /// &lt;returns&gt;hexa decimal string&lt;/returns&gt;
        public static string IntegerToHex(int IntValue)
        {
            return IntValue.ToString(&quot;X&quot;);
        }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/csharp/hexadecimal-to-decimal-vice-versa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hexadecimal string to Bytes array</title>
		<link>http://www.ms.oyangudi.com/blog/csharp/hexadecimal-string-to-bytes-array/</link>
		<comments>http://www.ms.oyangudi.com/blog/csharp/hexadecimal-string-to-bytes-array/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 03:51:01 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Hexadecimal string to Bytes array]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/?p=31</guid>
		<description><![CDATA[/// &#60;summary&#62; /// Hexa decimal to Byte array /// &#60;/summary&#62; /// &#60;param name=&#34;HexString&#34;&#62;Hexa decimal string&#60;/param&#62; /// &#60;returns&#62;byte array&#60;/returns&#62; public static byte[] HexToBytes(String hexString) { byte[] byteArray = null; int byteCount = 0; if (hexString != null &#38;&#38; hexString.Length &#62; 0) { // make sure we have an even number of characters if (hexString.Length % 2 [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: csharp;">

        /// &lt;summary&gt;
        /// Hexa decimal to Byte array
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;HexString&quot;&gt;Hexa decimal string&lt;/param&gt;
        /// &lt;returns&gt;byte array&lt;/returns&gt;
        public static byte[] HexToBytes(String hexString)
        {
            byte[] byteArray = null;
            int byteCount = 0;

            if (hexString != null &amp;&amp; hexString.Length &gt; 0)
            {
                // make sure we have an even number of characters
                if (hexString.Length % 2 != 0)
                    hexString = &quot;0&quot; + hexString;

                byteCount = hexString.Length / 2;
                byteArray = new byte[byteCount];
                string sTemp;

                for (int i = 0; i &lt; byteCount; i++)
                {
                    sTemp = hexString.Substring(i * 2, 2);
                    byteArray[i] = Convert.ToByte(sTemp, 16);
                }
            }

            return byteArray;
        }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/csharp/hexadecimal-string-to-bytes-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bytes array to Hexadecimal string</title>
		<link>http://www.ms.oyangudi.com/blog/csharp/bytes-array-to-hexadecimal-string/</link>
		<comments>http://www.ms.oyangudi.com/blog/csharp/bytes-array-to-hexadecimal-string/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 03:47:15 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Bytes array to Hexadecimal string]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/?p=30</guid>
		<description><![CDATA[/// &#60;summary&#62; /// Byte array to Hexa decimal string /// &#60;/summary&#62; /// &#60;param name=&#34;bytes&#34;&#62;byte array&#60;/param&#62; /// &#60;returns&#62;hexa decimal string&#60;/returns&#62; public static string BytesToHex(byte[] bytes) { string hex = BitConverter.ToString(bytes); return hex.Replace(&#34;-&#34;, &#34;&#34;); } /// &#60;summary&#62; /// Byte array to Hexa decimal string /// &#60;/summary&#62; /// &#60;param name=&#34;bytes&#34;&#62;byte array&#60;/param&#62; /// &#60;param name=&#34;includeHyphen&#34;&#62;bool include hyphen&#60;/param&#62; /// &#60;returns&#62;hexa [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: csharp;">

        /// &lt;summary&gt;
        /// Byte array to Hexa decimal string
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;bytes&quot;&gt;byte array&lt;/param&gt;
        /// &lt;returns&gt;hexa decimal string&lt;/returns&gt;
        public static string BytesToHex(byte[] bytes)
        {
            string hex = BitConverter.ToString(bytes);

            return hex.Replace(&quot;-&quot;, &quot;&quot;);
        }

        /// &lt;summary&gt;
        /// Byte array to Hexa decimal string
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;bytes&quot;&gt;byte array&lt;/param&gt;
        /// &lt;param name=&quot;includeHyphen&quot;&gt;bool include hyphen&lt;/param&gt;
        /// &lt;returns&gt;hexa decimal string&lt;/returns&gt;
        public static string BytesToHex(byte[] bytes, bool includeHyphen)
        {
            string hex = BitConverter.ToString(bytes);

            return hex;
        }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/csharp/bytes-array-to-hexadecimal-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auto Complete ComboBox &#8211; C# Windows Forms</title>
		<link>http://www.ms.oyangudi.com/blog/csharp/auto-complete-combobox-c-windows-forms/</link>
		<comments>http://www.ms.oyangudi.com/blog/csharp/auto-complete-combobox-c-windows-forms/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 04:38:37 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Auto Complete ComboBox]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/?p=26</guid>
		<description><![CDATA[Download source files &#8211; 8.50 Kb Download demo project &#8211; 11.0 Kb Introduction This is a simple code snippet which is used to make an Auto Complete ComboBox. Using the code Usage: Call the function AutoComplete from within the ComboBox&#8217;s KeyPress event handler. AutoComplete(ComboBox cb, System.Windows.Forms.KeyPressEventArgs e, bool blnLimitToList) Code /// &#60;summary&#62; /// AutoComplete /// [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li><a href="http://www.ms.oyangudi.com/blog/wp-content/uploads/AutoCompleteComboBoxCWindowsForms_14763/AutoCompleteComboBox_src_cs.zip">Download source files &#8211; 8.50 Kb</a> </li>
<li><a href="http://www.ms.oyangudi.com/blog/wp-content/uploads/AutoCompleteComboBoxCWindowsForms_14763/AutoCompleteComboBox_demo_cs.zip">Download demo project &#8211; 11.0 Kb</a> </li>
</ul>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="AutoComplete" border="0" alt="AutoComplete" src="http://www.ms.oyangudi.com/blog/wp-content/uploads/AutoCompleteComboBoxCWindowsForms_14763/AutoComplete.gif" width="320" height="288" /> </p>
<h4>Introduction</h4>
<p>This is a simple code snippet which is used to make an <b>Auto Complete ComboBox</b>. </p>
<h4>Using the code</h4>
<p><b>Usage:</b> Call the function AutoComplete from within the ComboBox&#8217;s KeyPress event handler. </p>
<div>
<pre class="brush: csharp;">

AutoComplete(ComboBox cb, System.Windows.Forms.KeyPressEventArgs e, bool blnLimitToList)
</pre>
</div>
<h4>Code</h4>
<div>
<pre class="brush: csharp;">

        /// &lt;summary&gt;
        /// AutoComplete
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;cb&quot;&gt;ComboBox&lt;/param&gt;
        /// &lt;param name=&quot;e&quot;&gt;KeyPressEventArgs&lt;/param&gt;
        /// &lt;param name=&quot;blnLimitToList&quot;&gt;Limit to List&lt;/param&gt;
		public void AutoComplete(ComboBox cb, System.Windows.Forms.KeyPressEventArgs e, bool blnLimitToList)
		{
			string strFindStr = &quot;&quot;;

			if (e.KeyChar == (char)8)
			{
				if (cb.SelectionStart &lt;= 1)
				{
					cb.Text = &quot;&quot;;
					return;
				}

				if (cb.SelectionLength == 0)
					strFindStr = cb.Text.Substring(0, cb.Text.Length - 1);
						else
					strFindStr = cb.Text.Substring(0, cb.SelectionStart - 1);
					}
			else
			{
				if (cb.SelectionLength == 0)
					strFindStr = cb.Text + e.KeyChar;
				else
					strFindStr = cb.Text.Substring(0, cb.SelectionStart) + e.KeyChar;
			}

			int intIdx = -1;

			// Search the string in the ComboBox list.

			intIdx = cb.FindString(strFindStr);

			if (intIdx != -1)
			{
				cb.SelectedText = &quot;&quot;;
				cb.SelectedIndex = intIdx;
				cb.SelectionStart = strFindStr.Length;
				cb.SelectionLength = cb.Text.Length;
				e.Handled = true;
			}
			else
			{
				e.Handled = blnLimitToList;
			}
		}
</pre>
</div>
<h4>History</h4>
<p>Released on November 8th 2006. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/csharp/auto-complete-combobox-c-windows-forms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DataGrid Paging using DataReader &#8211; C# Windows Forms</title>
		<link>http://www.ms.oyangudi.com/blog/csharp/datagrid-paging-using-datareader-c-windows-forms/</link>
		<comments>http://www.ms.oyangudi.com/blog/csharp/datagrid-paging-using-datareader-c-windows-forms/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 04:36:48 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[DataGrid Paging using DataReader]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/?p=25</guid>
		<description><![CDATA[Download source files &#8211; 21.5 Kb Download demo project &#8211; 8.0 Kb Introduction This is an example of Windows Forms DataGrid paging using c#. I have used Microsoft SQL Server 2000 database. Using the code Create a table: create table tblEmp ( E_ID int primary key , E_Name varchar(60) , E_Salary money , E_DOJ datetime [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li><a href="http://www.ms.oyangudi.com/blog/wp-content/uploads/DataGridPagingusingDataReaderCWindowsFor_145C2/DataGridPaging_DataReader_src_cs.zip">Download source files &#8211; 21.5 Kb</a> </li>
<li><a href="http://www.ms.oyangudi.com/blog/wp-content/uploads/DataGridPagingusingDataReaderCWindowsFor_145C2/DataGridPaging_DataReader_demo_cs.zip">Download demo project &#8211; 8.0 Kb</a> </li>
</ul>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="DataGridPaging_DataReader" border="0" alt="DataGridPaging_DataReader" src="http://www.ms.oyangudi.com/blog/wp-content/uploads/DataGridPagingusingDataReaderCWindowsFor_145C2/DataGridPaging_DataReader.gif" width="400" height="340" /> </p>
<h4>Introduction</h4>
<p>This is an example of Windows Forms DataGrid paging using c#. I have used Microsoft SQL Server 2000 database. </p>
<h4>Using the code</h4>
<p>Create a table: </p>
<div>
<pre class="brush: csharp;">

create table tblEmp
    (
      E_ID int primary key ,
      E_Name varchar(60) ,
      E_Salary money ,
      E_DOJ datetime
    )
go
</pre>
</div>
<p>Public variables: </p>
<div>
<pre class="brush: csharp;">

		/// &lt;summary&gt;
		/// Required designer variable.
		/// &lt;/summary&gt;

		// Protected Connection.
		protected SqlConnection mcnSample;

		// Page
		private int mintTotalRecords = 0;
		private int mintPageSize = 0;
		private int mintPageCount = 0;
		private int mintCurrentPage = 1;

		// Connection String
		protected const string CONNECTION_STRING = &quot;Server=localhost;UID=sa;PWD=;Database=Sample&quot;;
</pre>
</div>
<p>fillGrid() method: </p>
<div>
<pre class="brush: csharp;">

		private void fillGrid()
		{
			// For Page view.
			this.mintPageSize = int.Parse(this.tbPageSize.Text);
			this.mintTotalRecords = getCount();
			this.mintPageCount = this.mintTotalRecords / this.mintPageSize;

			// Adjust page count if the last page contains partial page.
			if (this.mintTotalRecords % this.mintPageSize &gt; 0)
				this.mintPageCount++;

			this.mintCurrentPage = 0;

			loadPage();
		}
</pre>
</div>
<p>getCount() method: This method gets the record count much faster than SELECT COUNT(*) statement. </p>
<div>
<pre class="brush: csharp;">

		private int getCount()
		{
			// This select statement is very fast compare to SELECT COUNT(*)
			string strSql = &quot;SELECT Rows FROM SYSINDEXES WHERE Id = OBJECT_ID('tblEmp') AND IndId &lt; 2&quot;;
			int intCount = 0;

			SqlCommand cmd = this.mcnSample.CreateCommand();
			cmd.CommandText = strSql;

			intCount = (int) cmd.ExecuteScalar();
			cmd.Dispose();

			return intCount;
		}
</pre>
</div>
<p>loadPage() method: </p>
<div>
<pre class="brush: csharp;">

		private void loadPage()
		{
			string strSql = &quot;&quot;;
			int intSkip = 0, i = 0;
			SqlDataReader dr;
			DataSet ds;
			DataTable dt;

			intSkip = (this.mintCurrentPage * this.mintPageSize);

			strSql = &quot;SELECT * FROM tblEmp&quot;;

			SqlCommand cmd = this.mcnSample.CreateCommand();
			cmd.CommandText = strSql;

			dr = cmd.ExecuteReader();
			ds = new DataSet();

			dt = ds.Tables.Add(&quot;tblEmp&quot;);

			// Add the table columns.
			for (i = 0; i &lt; dr.FieldCount; i++)
				dt.Columns.Add(dr.GetName(i), dr.GetFieldType(i)); 

			int intIdx = 0;
			while (dr.Read())
			{
				if (intIdx &gt;= intSkip)
				{
					DataRow r = dt.NewRow();

					// Assign DataReader values to DataRow.
					for (i = 0; i &lt; dr.FieldCount; i++)
						r[i] = dr[i];

					dt.Rows.Add(r);
				}

				if ((intIdx - intSkip) &gt;= (this.mintPageSize - 1))
					break;

				intIdx++;
			}

			dr.Close();

			// Populate Data Grid
			this.dgEmp.DataSource = ds.Tables[&quot;tblEmp&quot;].DefaultView;

			// Show Status
			this.lblStatus.Text = (this.mintCurrentPage + 1).ToString() + &quot; / &quot; + this.mintPageCount.ToString();

			cmd.Dispose();
			ds.Dispose();
		}
</pre>
</div>
<p>For page navigation: </p>
<div>
<pre class="brush: csharp;">

		private void goFirst()
		{
			this.mintCurrentPage = 0;

			loadPage();
		}

		private void goPrevious()
		{
			if (this.mintCurrentPage == this.mintPageCount)
				this.mintCurrentPage = this.mintPageCount - 1;

			this.mintCurrentPage--;

			if (this.mintCurrentPage &lt; 1)
				this.mintCurrentPage = 0;

			loadPage();
		}

		private void goNext()
		{
			this.mintCurrentPage++;

			if (this.mintCurrentPage &gt; (this.mintPageCount - 1))
				this.mintCurrentPage = this.mintPageCount - 1;

			loadPage();
		}

		private void goLast()
		{
			this.mintCurrentPage = this.mintPageCount - 1;

			loadPage();
		}
</pre>
</div>
<h4>History</h4>
<p>Released on November 9th 2006. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/csharp/datagrid-paging-using-datareader-c-windows-forms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
