I’m searching inside some controls in my WinForms Form, with the help of foreach statements.
I’m comparing the object i find through a “is”-reference (a is DataGridView). With “a” being an object in a control collecion.
That works fine so far, because the compared objects on my form are all sufficiantly different from one another.
In a new form i created i’m using a derived version of a DataGridView called my_datagridview. So when a my_datagridview is compared to a DataGridView through a “is”-reference no exception is thrown, which is “wrong” cause i want to handle the two seperately.
Is there a way to compare my_datagridview and DataGridView properly?
One option would be to use something like:
Or you could use
GetType()to match exactly, of course. The important question is what you would want to happen with any other classes derived fromDataGridViewor even fromMyDataGridView.