473,395 Members | 2,468 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,395 software developers and data experts.

datagird "Index out of array bound" exception

When the datagrid has multi rows and the vertical scrollbar hasn't appeared,
if I click the column near the bound or drag horizontal scrollbar, this
exception will be throwed. The trace stack as follows:

at System.Windows.Forms.DataGrid.CreateScrollableRegi on(Rectangle scroll)
at System.Windows.Forms.DataGrid.set_HorizontalOffset (Int32 value)
at System.Windows.Forms.DataGrid.ScrollRight(Int32 columns)\
at System.Windows.Forms.DataGrid.ScrollToColumn(Int32 targetCol)
at System.Windows.Forms.DataGrid.EnsureVisible(Int32 row, Int32 col)
at System.Windows.Forms.DataGrid.set_CurrentCell(Data GridCell value)
at System.Windows.Forms.DataGrid.OnMouseDown(MouseEve ntArgs e)
at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button,
Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
..
..
..

My datasource is a datatable.
IDE: .net 2003 + framework 1.1 + sp1
Does anyone know whether this is the DataGrid own bug?
What can I do to workaground it or resolve it?
Thanks.
Apr 24 '07 #1
3 2426
This exception can be thrown when you are altering the data in the bound
DataSource but you dont update the DataGrid. So it trys to show rows that arent
available anymore.
Check if the RaiseListChangedEvents-Property of the underlying bindingSource is set.

I hope that helps.
Greets
Apr 24 '07 #2
Hi Peter,

Thank you for your reply.

My case is: Anytime I udpate the bound DataSource, I rebind the DataGrid to
new DataSource. This exception only occurs when the DataGrid has more than
one rows and the vertical scrollbar hasn't appeared. But if the DataGrid has
only one row or the vertical scrollbar has appeared, anything is ok.

Follows is the code:
private void UpdateGrid()
{
this.m_grid.ReadOnly = false;
DataTable dt = (DataTable)this.m_grid.DataSource;
dt.Clear();
int numColumns = PageVersionsEditor.FixedColumns.Length;
if ( this.m_showDefaultVersionColumn )
numColumns += 1;
numColumns += this.m_allZones.Count;
for( int iVersion = 0; iVersion < this.m_versions.Count;
iVersion++ )
{
Version ver = (Version)this.m_versions[iVersion];
int column = 0;

object[] row = new object[numColumns];

row[column++] = iVersion+1;

// Default version
if ( this.m_showDefaultVersionColumn )
{
row[column++] = ver.IsDefault();
}

foreach ( Zone z in this.m_allZones )
{
row[column++] = ver.HasZone(z.name);
}

dt.Rows.Add(row);
}
this.m_grid.DataSource = dt;
this.m_grid.ReadOnly = true;
}

What happened?

Thanks & Regard,
Cymer
Apr 25 '07 #3
And I'm very sorry that my framework is 1.1, RaiseListChangedEvents only be
supported from 2.0.
Apr 25 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Eugene | last post by:
Hello all, I've been trying to figure this out for a few days now, and still have no clue what's going on... I have a few related tables in MS Access (Clients, Cars, Sales), and a datagrid,...
1
by: Clark Choi | last post by:
I ran the sample application called Petstore from msdn. Everything went fine until I tested Update button on the web form to update the database through Datagrid. I have been searching the web to...
4
by: Antoine | last post by:
Herfried and Cor:- I used tracing and actually tracked down the code that was causing the problem most likely. I wonder if you wanted to comment on it. Also I wonder if there is a better way...
0
by: Andrea | last post by:
My C# application is a drop target for the drop format Shell IDList Array I have some problems actually getting the data. I was using the same code used for the FileDrop data target but I'm...
3
by: writebrent | last post by:
I wrote a little interface for users to post data to a website. On their local machines, it produces CSV from an Excel spreadsheet, then posts it to the site. In some cases, the CSV will contain...
0
by: =?Utf-8?B?Q3ltZXI=?= | last post by:
When the datagrid has multi rows and the vertical scrollbar hasn't appeared, if I click the column near the bound or drag horizontal scrollbar, this exception will be throwed. The trace stack as...
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
5
by: Pseudonyme | last post by:
Dear All : Ever had an httpd error_log bigger than the httpd access log ? We are using Linux-Apache-Fedora-Httpd 2006 configuration. The PHP lines code that lead too tons of errors are : ...
1
BeemerBiker
by: BeemerBiker | last post by:
Using GridView and SqlDataSource I found that an index field defaults to "ReadOnly=True" and I have to change it to False and then hide it before my sql UPDATE command works. This seems awkward and...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.