Solved

DataGridView Guru?

Posted on 2006-10-19
3
1,552 Views
Last Modified: 2008-01-09
I need to do something a bit odd with a datagridview ... basically I need it to support edit mode but I want certain columns to not be tab stops ...

i.e.
column1   column2   column3
          5             6              7

edit in column1 hit tab and have it skip column2 and go directly to column3 ... any ideas?

Cheers,

Greg
0
Comment
Question by:gregoryyoung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 37

Author Comment

by:gregoryyoung
ID: 17770860
and to be clear this is winforms.
0
 
LVL 37

Author Comment

by:gregoryyoung
ID: 17771006
btw: I have tried this and some other ways of getting this behavior ...


void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == columntoskip)
            {
                this.dataGridView1.CurrentCell = this.dataGridView1[e.RowIndex, e.ColumnIndex + 1];
            }
        }

this gives an exception due to re-entracy
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 17771728
here is how to do it ... in case anyone finds this on the PAQ. This is for forward tabbing only butsupporting it for backwards tabbing (shift tab) would be rather simple.

    public class SkipColumnsDataGridView : DataGridView
    {
        private List<int> ColumnsToSkip = new List<int>();
        public SkipColumnsDataGridView(int[] toSkip)
        {
            ColumnsToSkip.AddRange(toSkip);
        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            Keys key = (keyData & Keys.KeyCode);
            int Location = this.CurrentCellAddress.X;
            if (ColumnsToSkip.Contains(Location))
            {
                if (key == Keys.Tab)
                {
                    do
                    {
                        this.ProcessTabKey(keyData);
                    } while (ColumnsToSkip.Contains(this.CurrentCellAddress.X));
                    return this.ProcessTabKey(keyData);
                }
            }
            return base.ProcessDialogKey(keyData);
        }
        protected override bool ProcessDataGridViewKey(KeyEventArgs e)
        {
            int Location = this.CurrentCellAddress.X;
            if (ColumnsToSkip.Contains(Location))
            {

                if (e.KeyCode == Keys.Tab)
                {
                    do
                    {
                        this.ProcessTabKey(e.KeyData);
                    } while (ColumnsToSkip.Contains(this.CurrentCellAddress.X));
                    return this.ProcessTabKey(e.KeyData);
                }
            }
            return base.ProcessDataGridViewKey(e);
        }
    }
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question