Solved

DataGridView Guru?

Posted on 2006-10-19
3
1,546 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now