Home > Net >  Traversal time frame between assigned to text boxes
Traversal time frame between assigned to text boxes

Time:01-29

Why would traverse in the process of the index went beyond the bounds of an array of problems? Does anyone help to look at the

CodePudding user response:

You look the debug coltxtSpend should be an empty array, no object index 0, so complains

CodePudding user response:

reference 1/f, wild puma snail reply:
debug you look at the coltxtSpend should be an empty array, no object index 0, so complains

No, even change coltxtSpeed inside the value of the wrong,

CodePudding user response:

An array is empty, you change the value of course no, are you sure there are 1000 textbox controls you form? And also is the textbox1, textbox2,... Textbox1000? If there is no 1000 such Controls, the Controls. Find the return value is empty, because he didn't Find Controls, understand???????

CodePudding user response:

The
refer to the third floor of the wild puma snail reply:
array is empty, you change the value of course no, are you sure you form 1000 a textbox control? And also is the textbox1, textbox2,... Textbox1000? If there is no 1000 such Controls, the Controls. Find the return value is empty, because he didn't Find Controls, understand???????

Do not have so much , I'm just test, there are 74, that according to such a thing is not found? Inside but I do have 74 textBox, but also in order,

CodePudding user response:

The 74 can be found, but continue to cycle will be an error

CodePudding user response:

You should use the while, not for, not only 74, 1000, when 75 so coltxtSpend is empty, take the first, of course, you will be prompted beyond index
Or you add a judge coltxtSpend length, only the length is greater than 0 to execute the code below

CodePudding user response:

Whether after the find is empty, and condition
Circulation is recommended to use the while loop ends when empty

CodePudding user response:

refer to the fifth floor of the wild puma snail reply:
these 74 can be found, but continue to cycle will be an error

That I have any way to improve? Use the while, how can I judge this form I of the text box?

CodePudding user response:

I'm still a little don't understand, I set the length of only 74, isn't it? Why can find 75?

CodePudding user response:

refer to 7th floor geek poet's reply:
whether after the find is empty, and as a condition
Circulation is recommended to use the while loop ends when empty

Oh, I see a little bit, I have a try,

CodePudding user response:

Bule, 9/f,
reference blue reply:
I'm still a little don't understand, I don't decide the length of only 74? Why can find 75?

You are for 1000, more than 75
Bool flag=true;
Int I=1;
While (flag)
{
//find a textbox + I
//if so, do you want to deal with the
//if not, set the flag=false, no longer continue to find
}

CodePudding user response:

You do this to maintain very troublesome, if someone changes the name textbox, which one you don't even know what changes, to debug for a long time

CodePudding user response:

11 references wtnu200 response:
Quote: Bule, 9/f, reference blue reply:
I'm still a little don't understand, I don't decide the length of only 74? Why can find 75?

You are for 1000, more than 75
Bool flag=true;
Int I=1;
While (flag)
{
//find a textbox + I
//if so, do you want to deal with the
//if not, set the flag=false, no longer continue to find
}

Or not, when carries on the control switch or at the wrong is this a TextBox TextBox=coltxtSpeed [0] as the TextBox

CodePudding user response:

refer to 12 floor ManBOyyy reply:
you do maintenance is very troublesome, if someone changes the name textbox, which one you don't even know what changes, to debug long

What does simple method, the time is the time frame after another time

CodePudding user response:

This kind of a certain number, the name can't strictly confirm the scene with the foreach better, of course, back to your code, use less than circulation, may be I didn't fully understand your needs,
Assuming you for each of the DateTimePicker created corresponding TextBox, hope after each DateTimePicker choose the time, the time is assigned to the corresponding TextBox,
The correct way is: each DateTimePicker only when the changes in operating their corresponding the TextBox, rather than a random DateTimePicker change later, read all the DateTimePicker and then update all the TextBox,
In this case, the need to tell the DateTimePicker, it corresponds to what is TextBox, many methods, such as the name of the TextBox endures DateTimePicker Tag, or allow them to keep the same naming rules, DateTimePicker dtp0, dtp1 dtp2... (or dtpA, dtpB, dtpC,... ), the corresponding TextBox called txt0, txt1 txt2... (or called txtA txtB txtC... )

Focus is: human strictly set the variable name, or the Tag attributes, can ensure that don't make a mistake,
Focus is: human strictly set the variable name, or the Tag attributes, can ensure that don't make a mistake,
Focus is: human strictly set the variable name, or the Tag attributes, can ensure that don't make a mistake,

 private void DateTimePicker_ValueChanged (object sender, EventArgs e) 
{
DateTimePicker DTP=sender as DateTimePicker;

//if because set error, this sentence is likely to find a null result, but this error is completely avoided, so did not join the null judgments
TextBox=TextBox Controls. The Find (DTP. Tag. The ToString (), true). OfType (). The First ();
//if you can't entirely avoid can't find the TextBox (this kind of situation really doesn't happen), can be changed to
//the TextBox=TextBox Controls. The Find (DTP. Tag. The ToString (), true). FirstOrDefault () as TextBox.
//if (textBox is null)
//{
//DoSomeThing ();
//}

TextBox. Text=DTP. Value. ToString (" MM - dd yyyy - HH: MM: ss. The FFF ");

//if you don't change the name of the textBox to Tag, but use the same naming rules for corresponding relationship, use the following method to find textBox
TextBox textBox2=Controls. The Find (DTP) Name) Replace (" DTP, "" TXT"), true). OfType (). The First ();
}

Binding for all the DateTimePicker ValueChanged event this method can, of course this movement can also be done in code,
 public _click () 
{
InitializeComponent();
Foreach (var DTP in Controls. OfType ())
{
The DTP. ValueChanged +=DateTimePicker_ValueChanged;
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related