[RESOLVED] TabPage index is invalid but visible?
I am invalidating a new column of a DataGridview (that resides on TabPages(1) of TabControl2 on Form1) from another class, which has worked successfully until now. Recently, the line of code below starting throwing the exception "System.ArgumentOutOfRangeException: 'InvalidArgument=Value of '1' is not valid for 'index'."
At run-time, immediately before execution of this line of code, I can see the data on the DGV but the tabs are invisible.
Code:
Dim main As Form1 = CType(Application.OpenForms(0), Form1)
For j = 1 To NumNewCols
CType(main.TabControl2.TabPages(1).Controls("dgv1"), DataGridView).InvalidateColumn(NumOrigCols + j - 1)
Next
FYI - there is no threading involved. There is a delegate to the DGV which is used when the DGV is updated from a threaded method inside a class -- which works fine during threading.
I also tried looping through the tabpages on this control, and there were none, but the data in the DGV are visible during the invalidate procedure(?)
What would cause this exception to be thrown now, when it was never thrown before?
Re: TabPage index is invalid but visible?
Have you looked at the stack trace of the exception to see exactly where the exception is being thrown? You should always start by establishing exactly what problem it is that you're trying to solve.
Re: TabPage index is invalid but visible?
This was resolved, since threading was being used. A delegate was applied, which resolved the tabcontrol issues.