473,806 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IndexOutOfRange Exception

5 New Member
Hi,

My form has a grid and the datasource the grid is an array. There is an event which adds records to the array and assigns the array as the datasource to the grid. When I just click on the grid, on any cell, it throws an exception on the Program.cs file

static void Main(string[] Args) {
try {
Application.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (false);
Application.Run (new frmMain(Args));
}
catch (IndexOutOfRang eException ex) {
throw ex;
}
}

The error given is
"Index -1 does not have a value."

messageLogList. Add(messageLog) ;

gridView = grdMessageLog;
gridView.DataSo urce = null;
gridView.AutoGe nerateColumns = false;
gridView.DataSo urce = messageLogList;
gridView.Refres h();
return;

Cannot understand, why it is throwing an error while I click on the grid.
Mar 28 '07 #1
5 2606
misra
5 New Member
Hi,

My form has a grid and the datasource the grid is an array. There is an event which adds records to the array and assigns the array as the datasource to the grid. When I just click on the grid, on any cell, it throws an exception on the Program.cs file

static void Main(string[] Args) {
try {
Application.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (fals e);
Application.Run (new frmMain(Args));
}
catch (IndexOutOfRang eException ex) {
throw ex;
}
}

The error given is
"Index -1 does not have a value."

messageLogList. Add(messageLog) ;

gridView = grdMessageLog;
gridView.DataSo urce = null;
gridView.AutoGe nerateColumns = false;
gridView.DataSo urce = messageLogList;
gridView.Refres h();
return;

Cannot understand, why it is throwing an error while I click on the grid.

--------------------------------------------------------------------------------
Mar 28 '07 #2
kenobewan
4,871 Recognized Expert Specialist
Please don't repost your questions. What debugging have you tried? Thanks.
Mar 28 '07 #3
misra
5 New Member
I have debugged by using try catch blocks on each method. Even then the exception is caught at the Program.cs, which does not provide any extra information about the cause of the exception.
I am not able to get actually what code is throwing the exception which is causing a problem in troubleshooting .
Mar 29 '07 #4
Hemantchaudhari
7 New Member
check again ur starting index and termination condition.

may be one of them is wrong.

u r sure that both are correct?
Mar 29 '07 #5
misra
5 New Member
I found that in a datagridview problem, if one has something like

dgvGrid.DataSou rce = myObject.Collec tionProperty;
bsBindingSource .DataSource = myObject.Collec tionProperty;
dgvGrid.DataSou rce = bsBindingSource ;

then adding the following line after the object is added to the collection, fixes the problem

bsBindingSource .ResetBindings( false);
Mar 29 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2768
by: Nicolas Fleury | last post by:
Hi, I've made a small utility to re-raise an exception with the same stack as before with additional information in it. Since I want to keep the same exception type and that some types have very specific constructors (which take, for example, more than one parameter), the only safe way I have found to made it is by hacking the str representation: import sys
1
4233
by: Old Wolf | last post by:
1. What is the difference between #include <stdexcept> and #include <exception> ? 2. Is there a list somewhere of what each standard exception is used for? either to throw them, or throw user-defined exceptions derived from them? (for example I have been deriving mine from std::bad_alloc if there was a memory problem, or std::bad_exception if there was some other problem) 3. Is it a good idea to make all user-defined exceptions derive...
11
3280
by: Master of C++ | last post by:
Hi, I am writing a simulation package in C++, and so far I've written about 8000 lines of code and have about 30 classes. I haven't used C++ exceptions so far (for various reasons). The only two "resources" I use are memory and file I/O and whenever there is a memory allocation failure or file I/O failure I just simply call a custom assert-type function to check, print a error message and abort. This seems to be OK for now (for the...
4
15843
by: maricel | last post by:
I have the following base table structure - DDL: CREATE TABLE "ADMINISTRATOR"."T1" ( "C1" INTEGER NOT NULL ) IN "TEST_TS" ; ALTER TABLE "ADMINISTRATOR"."T1" ADD PRIMARY KEY
5
5822
by: PCC | last post by:
I am using the Exception Managment Application Block on Windows Server 2003 Enterprise and .NET v1.1. If I use the block with an ASP.NET web wervice or in a web application I get the following error: ------------------------------------ System.Security.SecurityException: The event source ExceptionManagerInternalException does not exist and cannot be created with
2
1437
by: Alex | last post by:
Hi. What would happen if an exception occurs inside a Finally block and at the same time inside the try another exception was thrown without been handled by any catch? Alejandro.
44
4236
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level user tasks should always be included in a try/catch block that actually handles any exceptions that occur (log the exception, display a message box, etc.). 2. Low-level operations that are used to carry out the high level tasks
2
1295
by: Iwan Petrow | last post by:
Hi, I have two tables with relation: Table1: T1_id T2_id (foreign key,allow null) ..... Table2
3
2513
by: JohnDeHope3 | last post by:
First let me say that I understand that Asp.Net wraps my exception in an HttpUnhandledException. I have found a lot of discussion about that on the web, which was informative, but not helpful. Let me explain how my question is different. Second, let me say that I have two questions. One is an ASP.Net related question. The other is a general System.Exception question. They are related but also individual. Okay here is my problem...
2
6996
by: Darko Miletic | last post by:
Recently I wrote a dll in c++ and to simplify the distribution I decided to link with multithreaded static library (/MT or /MTd option). In debug everything works fine but in release I get this: parseMetadata.obj : error LNK2001: unresolved external symbol "public: __thiscall std::exception::exception(void)" (??0exception@std@@QAE@XZ) 2>libcpmt.lib(string.obj) : error LNK2001: unresolved external symbol "public: __thiscall...
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10618
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10371
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.