Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Referring to textbox by array value

$
0
0
Hi all,

I have 6 textboxes, each of which has a number at the end of the name (1-6).I also have an array (numbers) holding 6 values.

I'm currently using the code below to place the array value in the corresponding textbox :-

                    foreach (Control ctl in Controls)
                    {
                        var box = ctl as TextBox;
                        if (box != null)
                        {
                            if (box.Name.Contains((x + 1).ToString()))
                            {
                                box.Text = numbers[x].ToString();
                                box.Refresh();
                            }
                        }
                    }


As I'm new to c#, I was wondering if there was a more elegant way of completing this task. I'd be glad of any help.

Thanks in advance.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>