Skip to content

Overloading .Net C# DataGridView For Auto Tabbing

August 20, 2012

I needed to auto tab across multiple fields in a datagridview we are using in our Epicor ERP system. I found it wasn’t that easy to do so I thought I would paste the code if anyone else has the same problem.

The actual code to do the tabbing is a hack but it works!


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyNameSpace
{
public class MyDataGridView : System.Windows.Forms.DataGridView
{

protected override bool ProcessDialogKey(Keys keyData)
{

if (keyData.Equals(System.Windows.Forms.Keys.Tab))
{
if (this.CurrentCell.ColumnIndex == 7)
{
base.ProcessEnterKey(Keys.Enter);
base.ProcessLeftKey(Keys.Left);
base.ProcessLeftKey(Keys.Left);
base.ProcessLeftKey(Keys.Left);
return false;
}
if (this.CurrentCell.ColumnIndex == 4)
{
base.ProcessTabKey(Keys.Tab);
base.ProcessTabKey(Keys.Tab);
base.ProcessTabKey(Keys.Tab);
}

}

return false;
}

}
}

Advertisements

From → .NET

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: