471,570 Members | 936 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

Noobie question

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[i] = the texbox.text
arr[i] = Convert.ToInt32(this.Controls[controlLocation].Text);
}

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

Thanks,
Jimmie

Feb 13 '06 #1
2 1673
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.
<ji******@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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[i] = the texbox.text
arr[i] = Convert.ToInt32(this.Controls[controlLocation].Text);
}

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

Thanks,
Jimmie

Feb 13 '06 #2
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.

<ji******@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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[i] = the texbox.text
arr[i] = Convert.ToInt32(this.Controls[controlLocation].Text);
}

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

Thanks,
Jimmie

Feb 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by special_agent69 | last post: by
6 posts views Thread by Aristotelis E. Charalampakis | last post: by
1 post views Thread by Aristotelis E. Charalampakis | last post: by
3 posts views Thread by maharg | last post: by
6 posts views Thread by gonzlobo | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.