Archive for January, 2013

How to Elegantly Add Row Numbering for DataGridView Tables

Saturday, January 26th, 2013

There are a few ways to go about adding row numbering for your DataGridView’s, but you have to ensure you have added the code in, where ever you are adding a new row. If your inserting a row, then you have to go back and update all your numbering. With the option shown here, you need not worry about updating any row numbers when working with the DataGridView.

DGV_RowPostPaint_01

Once you add the event for the ‘RowPostPaint’, the code (function header outlined in red) just needs to be updated to reference the routine (function header outlined in green). I keep the numbering routine in its own block of code so that is can be reused by other DataGridView tables on the same form.

private void dgv_CompanySites_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
bg_DGV_RowPostPaint(sender, e);
}

private void bg_DGV_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
     var bgDGV = sender as DataGridView;
    var bgRowIdx = (e.RowIndex + 1).ToString();

    var centerFormat = new StringFormat()
    {
        // right alignment might actually make more sense for numbers
        Alignment = StringAlignment.Center,
        LineAlignment = StringAlignment.Center
    };   

    var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, bgDGV.RowHeadersWidth, e.RowBounds.Height);
    e.Graphics.DrawString(bgRowIdx, this.Font, SystemBrushes.ControlText, headerBounds, centerFormat);
}

When you load your DataGridView, the RowPostPaint event will be raised to perform row level painting, after all cell painting has occurred. This renders your row numbering nicely, and you do not have to add any additional code for numbering when adding data rows.

The following example shows the numbering where the numbers are low in range:

DGV_RowPostPaint_03

As your numbering gets higher up in range, the spacing remains nicely proportioned:

DGV_RowPostPaint_02

Migrating BMC API Applications from 32 Bit WinXP + VS 2005 Express to 64 Bit Windows 7 + VS 2010 Express

Tuesday, January 8th, 2013

Migrating 32 Bit WinXP + VS 2005 Express to 64 Bit Windows 7 + VS 2010 Express

 I was recently upgraded from the 32 Bit WinXP operating system to the 64 Bit Windows 7. With the new OS, I figured it was probably time up move from VS 2005 Express to VS2010 Express, both of which are the C# flavour.

 First, none of my existing application would run on Windows 7. Ok, even using the XP compatibility mode wouldn’t work. The easy solution I figured was I would just have to recompile and magically everything would work fine. When I attempted to load my existing vs2005 projects into vs2010, the projects were successfully converted over by the wizard. Running/debugging the newly converted project resulted in some additional errors. Slowly each error was resolved and I finally had a solution that worked and was repeatable across all the small utilities I had (30 in total for 7.6.04. The other 57 applications for 7.1.x will probably never see an upgrade). Presented below are my steps that I have used.

 There are a number of documents and sites out there that will tell you how to install the .NET API for Remedy (ARSystem), but that gets thrown out the door with 64 Bit.

 You will need to locate and download the “ARAPI764_NET” zip file and extract its contents out to a folder. Below is the format that I have used to help keep everything organized. I have another folder (not shown below) called “Remedy Utilities” where the same sets of files are stored, but I also drop into this folder, all the executable files that I build. This way I have many applications all sharing the same set of library files.

 

 

 

 

You will not be able to register the BMC DLL files with the regasm for the 4.x Framework. This is due to the security changes made in this version. You’re running under 64 Bit, which again won’t work well with the BMC DLL files as they were compiled for 32 Bit.

Once your directories are setup, you just need to start converting over your VS2005 projects to VS2010.

The following link will allow you to download the PDF which contains the process that I have used successfully, along with screen shots (PDF seemed to be an easier format to reference):

 Updating existing projects to work with VS2010