Noobie question

  • Thread starter Thread starter jimi_xyz
  • Start date Start date
J

jimi_xyz

Hi,
I current have a from with 12 textboxes, and want to index all of them,
i keep getting this error..

'System.Windows.Forms.Control.ControlCollection' does not contain a
definition for 'IndexOfKey'

I figure its because the the function IndexOfKey is not defined.. here
is the code..

for (i = 0; i < 12; i++)
{
int controlLocation = this.Controls.IndexOfKey("textBox" +
i.ToString());

//Now we access that control through the form.control
//array and set arr = the texbox.text
arr = Convert.ToInt32(this.Controls[controlLocation].Text);
}

My question is what would the definition of IndexOfKey look like, and
where would it go??

Thanks,
Jimmie
 
Hi Jimmie,

I can understand your confusion. I believe it arises from using a property
of the System.Windows.Forms.Control.ControlCollection class in the .Net 2.0
Framework, with a class written for the .Net 1.1 Framework. The 2.0
System.Windows.Forms.Control.ControlCollection class *does* have an
IndexOfKey method, but the 1.1
System.Windows.Forms.Control.ControlCollection does not.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
 
Hi Jimmie,

I explained your problem but forgot to add a solution!

I would implement my own IndexOfKey method, to which you would pass an
instance of System.Windows.Forms.Control.ControlCollection, and a string
(the name of the Control you are looking for). It would loop through the
Collection, check the Name property of each Control, compare it to the name
passed, and stop when it found a match, returning the index at which it
stopped.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top