Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DataGridView Guru?

Posted on 2006-10-19
3
Medium Priority
?
1,555 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 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