471,078 Members | 828 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,078 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 2487
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

Post your reply

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

Similar topics

4 posts views Thread by Nicolas Fleury | last post: by
1 post views Thread by Old Wolf | last post: by
11 posts views Thread by Master of C++ | last post: by
4 posts views Thread by maricel | last post: by
2 posts views Thread by Alex | last post: by
44 posts views Thread by craig | last post: by
2 posts views Thread by Iwan Petrow | last post: by
3 posts views Thread by JohnDeHope3 | last post: by
reply views Thread by leo001 | last post: by

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.