Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have created a Custom Control in C# with following code
public bool _last;
        private void SupperDataGridView_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                e.SuppressKeyPress = true;
              
                int iColumn = this.CurrentCell.ColumnIndex;
                
                
                int iRow = this.CurrentCell.RowIndex;
                if (iColumn == this.Columns.Count - 1)
                {
                    if (iRow < this.Rows.Count - 1)
                    {
                        this.CurrentCell = this [0, iRow + 1];
                    }
                    else
                    {
                        _last = true;
                    }

                }
                else
                {
                    this.CurrentCell = this[iColumn +1,iRow];
                }
            }
        } 
This works fine in normal conditions, but, when i try to hide one or two columns, it gives me an error.

Can anyone help me with this code ? I want that when the user presses the enter-key the cursor should move to the right side rather than to the next row. If possible, if cell is blank, the cursor should jump to the next cell.
Posted
Updated 11-Nov-14 4:02am
v4
Comments
Kornfeld Eliyahu Peter 11-Nov-14 9:13am    
What error?

1 solution

I'm guessing you need to check the Visible property of the column.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.visible(v=vs.110).aspx[^]
 
Share this answer
 
Comments
Nikhil Bhivgade 11-Nov-14 9:23am    
i want to add custome property if user want to hide 2-3 column it should provide value and code should work according to that.
PIEBALDconsult 11-Nov-14 9:31am    
Yes. Yes it should. Go write that code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900