?
Solved

DataGridView Guru?

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 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