PC Review


Reply
Thread Tools Rate Thread

datagird "Index out of array bound" exception

 
 
=?Utf-8?B?Q3ltZXI=?=
Guest
Posts: n/a
 
      24th Apr 2007
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.CreateScrollableRegion(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(DataGridCell value)
at System.Windows.Forms.DataGrid.OnMouseDown(MouseEventArgs 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(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(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.
 
Reply With Quote
 
 
 
 
Peter Vitt
Guest
Posts: n/a
 
      24th Apr 2007
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
 
Reply With Quote
 
=?Utf-8?B?Q3ltZXI=?=
Guest
Posts: n/a
 
      25th Apr 2007
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
 
Reply With Quote
 
=?Utf-8?B?Q3ltZXI=?=
Guest
Posts: n/a
 
      25th Apr 2007
And I'm very sorry that my framework is 1.1, RaiseListChangedEvents only be
supported from 2.0.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"array index out of bounds" can't delete declined task message ocbizlaw Microsoft Outlook BCM 1 18th Jun 2008 05:00 PM
Datagrid exception "index was outside the bounds of the array" =?Utf-8?B?Q3ltZXI=?= Microsoft Dot NET 0 24th Apr 2007 09:04 AM
"Array index out of bounds" error when deleting Shortcut Group =?Utf-8?B?QnJldHQ=?= Microsoft Outlook Discussion 1 27th Feb 2007 04:57 PM
"Array index out of bounds" error when creating shortcut to .oft =?Utf-8?B?QnJldHQ=?= Microsoft Outlook Discussion 0 27th Feb 2007 04:45 PM
Error: "Index was outside the bounds of the array" when binding the datatable with datagrid Gerry Viator Microsoft ADO .NET 1 11th Jun 2004 06:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:12 PM.