473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

IndexOutOfRange Exception

5
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.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new frmMain(Args));
}
catch (IndexOutOfRangeException ex) {
throw ex;
}
}

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

messageLogList.Add(messageLog);

gridView = grdMessageLog;
gridView.DataSource = null;
gridView.AutoGenerateColumns = false;
gridView.DataSource = messageLogList;
gridView.Refresh();
return;

Cannot understand, why it is throwing an error while I click on the grid.
Mar 28 '07 #1
5 2585
misra
5
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.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new frmMain(Args));
}
catch (IndexOutOfRangeException ex) {
throw ex;
}
}

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

messageLogList.Add(messageLog);

gridView = grdMessageLog;
gridView.DataSource = null;
gridView.AutoGenerateColumns = false;
gridView.DataSource = messageLogList;
gridView.Refresh();
return;

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

--------------------------------------------------------------------------------
Mar 28 '07 #2
kenobewan
4,871 Expert 4TB
Please don't repost your questions. What debugging have you tried? Thanks.
Mar 28 '07 #3
misra
5
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
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
I found that in a datagridview problem, if one has something like

dgvGrid.DataSource = myObject.CollectionProperty;
bsBindingSource.DataSource = myObject.CollectionProperty;
dgvGrid.DataSource = 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
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...
1
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...
11
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...
4
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
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...
2
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
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...
2
by: Iwan Petrow | last post by:
Hi, I have two tables with relation: Table1: T1_id T2_id (foreign key,allow null) ..... Table2
3
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...
2
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: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.