Solved

DataGridView Guru?

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

732 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