Archive for Novembre 5th, 2007

DataGridView With Row Numbers

Novembre 5th, 2007

Description: Implementation of the System.Windows.Forms.DataGridView that shows automatically formatted and sized row numbers in the row header.

Link: http://www.codekeep.net/snippets/34d04a2b-7876-441a-b0ea-c5960dde2b7d.aspx

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace DataGridView2
{
    /// <summary>
    /// display a datagrid with row numbers
    /// </summary>
    class DataGridView2 : DataGridView
    {
        /// <summary>
        /// draw the row number on the header cell, auto adjust the column width
        /// to fit the row number
        /// </summary>
        /// <param name="e"></param>
        protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
        {
            base.OnRowPostPaint(e);

            // get the row number in leading zero format,
            //  where the width of the number = the width of the maximum number
            int RowNumWidth = this.RowCount.ToString().Length;
            StringBuilder RowNumber = new StringBuilder(RowNumWidth);
            RowNumber.Append(e.RowIndex + 1);
            while (RowNumber.Length < RowNumWidth)
                RowNumber.Insert(0, "0");

            // get the size of the row number string
            SizeF Sz = e.Graphics.MeasureString(RowNumber.ToString(), this.Font);

            // adjust the width of the column that contains the row header cells
            if (this.RowHeadersWidth < (int)(Sz.Width + 20))
                this.RowHeadersWidth = (int)(Sz.Width + 20);

            // draw the row number
            e.Graphics.DrawString(
                RowNumber.ToString(),
                this.Font,
                SystemBrushes.ControlText,
                e.RowBounds.Location.X + 15,
                e.RowBounds.Location.Y + ((e.RowBounds.Height - Sz.Height) / 2));
        }
    }
}

How To Increase Traffic to Your Blog

Novembre 5th, 2007

One important topic for blog owners is how to increase traffic, which is easier than it seems, once you know how. In this article, you’ll learn about 7 effective methods. By Terry Detty. 1105

Sunday of the week

Novembre 5th, 2007

Description: Given a date, returns the Sunday for the week where a week is Sunday through Saturday.

Link: http://www.codekeep.net/snippets/fff2f0fc-8820-4e37-ade6-b73d5d3d14b3.aspx

private DateTime getSunday(DateTime fromDate) {
    DateTime sunday = fromDate;
    if (fromDate.DayOfWeek != DayOfWeek.Sunday) {
	DateTime temp;
	int dow = (int)fromDate.DayOfWeek;
	temp = fromDate.AddDays(-dow);
	if (temp.DayOfWeek == DayOfWeek.Sunday) {
	    sunday = temp;
	}
    }
    return sunday;
}