A
A
Alexander Dorofeev2016-05-29 15:06:56
C++ / C#
Alexander Dorofeev, 2016-05-29 15:06:56

Why is InvalidCastException thrown?

You need to walk through TableLayoutPanel.ColumnStyles.
I use the usual one foreach:

foreach (ColumnStyle style in myTableLayout.ColumnStyles)
 {
     // произвожу свои действия
 }

Crashes System.InvalidCastExceptionon line ColumnStyle style in myTableLayout.ColumnStyles:
Failed to cast object type 'System.Windows.Forms.RowStyle' to type 'System.Windows.Forms.ColumnStyle' .
WTF?!
MDSN watched.
Rebuild and Clean - does not help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Dorofeev, 2016-05-30
@TechCloud

I don't know what it was, but after deleting the project directory
and re-cloning from the VCS , the problem disappeared.
Thanks to all!

T
Tsiren Naimanov, 2016-05-29
@ImmortalCAT

You have an erroneous type cast,
you are trying to cast the System.Windows.Forms.ColumnStyle type to System.Windows.Forms.RowStyle
, by mistake I won’t say anything more
like
MyClass != MySourceClass

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question