C#

.NET

Hexadecimal string to Bytes array

0

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

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

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

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

            return byteArray;
        }
.NET

Bytes array to Hexadecimal string

0

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

            return hex.Replace("-", "");
        }

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

            return hex;
        }
.NET

Auto Complete ComboBox – C# Windows Forms

3

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’s KeyPress event handler.


AutoComplete(ComboBox cb, System.Windows.Forms.KeyPressEventArgs e, bool blnLimitToList)

Code


        /// <summary>
        /// AutoComplete
        /// </summary>
        /// <param name="cb">ComboBox</param>
        /// <param name="e">KeyPressEventArgs</param>

More >

.NET

DataGrid Paging using DataReader – C# Windows Forms

0

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
    )
go

Public variables:


		/// <summary>

More >

.NET

DataGrid Paging – C# Windows Forms

0

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
    )
go

In this example, the loadPage() method fetches only the required page data from More >

.NET

String.Format Method

0

Integer

 

Add zeroes before number

   1: String.Format("{0:00000}", 15);          // "00015"
Go to Top