Problem solving when the control is running after the index is out of range

Source: Internet
Author: User

Error phenomena:

Error message: The index is out of range. Must be non-negative and less than the collection size.

Parameter name: Index (development environment: VS2010, Tri-party control DotNetBar)

Generally in the program development process of the above errors, generally in the program interface is no way to catch the exception, but it is not such a problem there is no way to solve, We can add code in the project's entry file: Program.cs: application.threadexception + = new System.Threading.ThreadExceptionEventHandler ( Application_threadexception);

static void Application_threadexception (object sender, System.Threading.ThreadExceptionEventArgs e)

{

MessageBox.Show (E.exception.message.tostring (), "warning", MessageBoxButtons.OK, messageboxicon.warning);

Logwrite (e);//writes exception information to the log file

}

This allows us to catch an exception and then collect data for further analysis of the cause of the exception.

The following are simple workarounds:

If you have the above control problems when you do the program development, and can determine which control has an exception, we can open the Design view of the interface in the development tool editing State, and then find the Assigned property item in the control's Properties window, optionally attach a value to the control to see if the compiler has an error, If an exception occurs when assigning a value to a control in an edit state, then we have a problem with our control, we just need to remove the original control and then drag it back into the new control. We need to be aware that we need to make a backup of the primary property values of the original control before we delete the original control and drag it into the new space. , assign the property value of the original control to the new control.

If you assign a value to a property item and the control does not show the error we ran in the Times, it indicates that there is no problem with our control, and then we need to check if there is a problem with the code that we have dynamically assigned to the control after we run it.

Problems with control indexing are resolved satisfactorily

Problem solving when the control is running after the index is out of range

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.