0

I'm selecting a cell in my DataGridView programmatically:

myDataGridView.CurrentCell = myDataGridView.Rows[index].Cells[0];

/* The codes is here is not executed */
MessageBox.Show("Here");

my first column (column with 0 index) is hidden and when this line of code is executed, it shows undefined behavior(don't execute the continuous of method). Is this normal?

Edit: My Question changed to why this unhandled exception is not caught by Visual Studio?

Ali.Sepehri
  • 139
  • 1
  • 1
  • 6
  • Could you explain better what is the behavior observed? – Steve Dec 01 '14 at 08:46
  • @Steve: The code after that line is not executed. it returns the method. – Ali.Sepehri Dec 01 '14 at 08:49
  • Show us which is this code maybe it doesn't have effect – faby Dec 01 '14 at 08:50
  • @faby: I'm debugging it and cursor doesn't go after that. I Also edit my code. – Ali.Sepehri Dec 01 '14 at 09:01
  • Do you have some try/catch around that code that swallows the exception? It seems something like a bad row index. Please show more code around that lines. In which event do you have this code? – Steve Dec 01 '14 at 09:06
  • @Steve: No, You're right. But why this is not caught by VS? – Ali.Sepehri Dec 01 '14 at 09:19
  • Does this behavior happens in VS while you are in a Form.Load event on a 64bit OS? http://stackoverflow.com/questions/4933958/vs2010-does-not-show-unhandled-exception-message-in-a-winforms-application-on-a – Steve Dec 01 '14 at 09:29

1 Answers1

1

Yes it is normal. The documentation for the CurrentCell property specifically states that an InvalidOperationException is thrown if:

The specified cell when setting this property is in a hidden row or column.

In future, if something doesn't work as you expect, make reading the relevant documentation the very first thing you do. It won't always give you the information you need but it often will. You should never be posting a question here or anywhere else without having read the relevant documentation first.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46