Click here to Skip to main content
15,906,558 members
Home / Discussions / C#
   

C#

 
QuestionRe: Object Null/Empty Check Pin
jojoba201114-Jun-10 22:50
jojoba201114-Jun-10 22:50 
AnswerRe: Object Null/Empty Check Pin
DaveyM6914-Jun-10 23:00
professionalDaveyM6914-Jun-10 23:00 
QuestionRe: Object Null/Empty Check Pin
jojoba201114-Jun-10 23:23
jojoba201114-Jun-10 23:23 
GeneralRe: Object Null/Empty Check Pin
Luc Pattyn15-Jun-10 0:55
sitebuilderLuc Pattyn15-Jun-10 0:55 
GeneralRe: Object Null/Empty Check Pin
DaveyM6915-Jun-10 1:07
professionalDaveyM6915-Jun-10 1:07 
AnswerRe: Object Null/Empty Check Pin
Eddy Vluggen14-Jun-10 23:04
professionalEddy Vluggen14-Jun-10 23:04 
QuestionAuto Generate Row Number [solved] Pin
Elango N14-Jun-10 22:12
Elango N14-Jun-10 22:12 
AnswerRe: Auto Generate Row Number Pin
Peace ON14-Jun-10 22:29
Peace ON14-Jun-10 22:29 
You can implement your custom datagridview by overriding it and then use it's OnRowPostPaint method
to draw row number.

That's it. No whenever you use this grid it will automatically add row number to the datagridview.
This is the simplest solution I have to apply row number in datagridview without any kind of looping.

C#
///
/// This class extends the the DataGridView so row numbers will
/// automatically appear in the row header cells. In this
/// implementation, the width of the column that contains the row
/// header cells is automatically adjusted to accomodate the row
/// numbering.
///
class MyDGV : DataGridView
{
    public MyDGV()
    {
        //perform any necessary customization initialization here

    } //end default constructor

    protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
    {
      //this method overrides the DataGridView's RowPostPaint event
      //in order to automatically draw numbers on the row header cells
      //and to automatically adjust the width of the column containing
      //the row header cells so that it can accommodate the new row
      //numbers,

        //store a string representation of the row number in 'strRowNumber'
        string strRowNumber = (e.RowIndex + 1).ToString();

        //prepend leading zeros to the string if necessary to improve
        //appearance. For example, if there are ten rows in the grid,
        //row seven will be numbered as "07" instead of "7". Similarly, if
        //there are 100 rows in the grid, row seven will be numbered as "007".
        while (strRowNumber.Length < this.RowCount.ToString().Length) strRowNumber = "0" + strRowNumber;

        //determine the display size of the row number string using
        //the DataGridView's current font.
        SizeF size = e.Graphics.MeasureString(strRowNumber, this.Font);

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

        //this brush will be used to draw the row number string on the
        //row header cell using the system's current ControlText color
        Brush b = SystemBrushes.ControlText;

        //draw the row number string on the current row header cell using
        //the brush defined above and the DataGridView's default font
        e.Graphics.DrawString(strRowNumber, this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));

        //call the base object's OnRowPostPaint method
        base.OnRowPostPaint(e);
    } //end OnRowPostPaint method
} //end class




HTH
Jinal Desai - LIVE
Experience is mother of sage....

Questionhow I could save apicture in sql and bring it to a form in C#? Pin
ronakT14-Jun-10 21:34
ronakT14-Jun-10 21:34 
AnswerRe: how I could save apicture in sql and bring it to a form in C#? Pin
Abhinav S14-Jun-10 22:12
Abhinav S14-Jun-10 22:12 
QuestionHaving A Spot Of Trouble With Events Pin
Roger Wright14-Jun-10 19:48
professionalRoger Wright14-Jun-10 19:48 
AnswerRe: Having A Spot Of Trouble With Events Pin
TheFoZ14-Jun-10 21:28
TheFoZ14-Jun-10 21:28 
GeneralRe: Having A Spot Of Trouble With Events Pin
Roger Wright15-Jun-10 7:06
professionalRoger Wright15-Jun-10 7:06 
AnswerRe: Having A Spot Of Trouble With Events Pin
DaveyM6914-Jun-10 22:21
professionalDaveyM6914-Jun-10 22:21 
QuestionTrackBar Pin
Nicolás Marzoni14-Jun-10 17:32
Nicolás Marzoni14-Jun-10 17:32 
AnswerRe: TrackBar Pin
Calla14-Jun-10 19:32
Calla14-Jun-10 19:32 
GeneralRe: TrackBar Pin
Nicolás Marzoni15-Jun-10 1:28
Nicolás Marzoni15-Jun-10 1:28 
GeneralRe: TrackBar Pin
DaveyM6915-Jun-10 1:31
professionalDaveyM6915-Jun-10 1:31 
GeneralRe: TrackBar Pin
Nicolás Marzoni15-Jun-10 1:36
Nicolás Marzoni15-Jun-10 1:36 
GeneralRe: TrackBar Pin
DaveyM6915-Jun-10 2:39
professionalDaveyM6915-Jun-10 2:39 
GeneralRe: TrackBar Pin
DaveyM6915-Jun-10 2:40
professionalDaveyM6915-Jun-10 2:40 
GeneralRe: TrackBar - Long post alert! Pin
DaveyM6915-Jun-10 10:17
professionalDaveyM6915-Jun-10 10:17 
QuestionAsp.Net MVC2 in VS 2010 Pin
Darrall14-Jun-10 12:03
Darrall14-Jun-10 12:03 
AnswerRe: Asp.Net MVC2 in VS 2010 Pin
Al Beback14-Jun-10 17:15
Al Beback14-Jun-10 17:15 
GeneralRe: Asp.Net MVC2 in VS 2010 Pin
Darrall15-Jun-10 3:37
Darrall15-Jun-10 3:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.