Skip to content

Invalid Cast

Jonathen Scalet

Asked Mar 29, 2006, 1:19 PM EST1 answer
Share
LinkedInX
I am trying to access a dynamically created control ( a tabpage ) with the following code:

((ListView)this.tabControl1.TabPages[1].Controls[1]).Items.Add("HELLO");

I am getting an error:
Specified cast is not valid.


What am I doing wrong?

Thanks,
Jon

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    the control at position 1 in that tab is clearly not a listview. I would suggest trying to call it by its name or loop through all the controls and compare their types to see which one is the listview.
    0