DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Thu, 2 Aug 2007 06:46:04 -0700,    posted on: microsoft.public.dotnet.framework.windowsforms.databinding        back       

Thread Index
  1    imran.a
          2    imran.a


DataGridView RowValidating IndexOutOfRangeException   
Hi all,
I am having a problem with inserting rows in to my datagridview control. The 
datagridview is bound to a bindingsource with a filter set. If i try and add 
a row to the datagridview while the filter is set i get an 
IndexOutOfRangeException specifying that the index of the row i have just 
added does not exist.

The exception occurs when i try and access the datagridview.currentrow 
property in my rowvalidating event handler, or alternatively 
datagridview.rows(e.rowindex).

        void ValidateRow(object sender, DataGridViewCellCancelEventArgs e)
        {
            DataGridView tmpDGV = ((DataGridView)sender);
            try
            {
                if (tmpDGV.IsCurrentRowDirty && tmpDGV.CurrentRow != null)
                {
                    if (Properties.Settings.Default.validation && 
RowHasValiadtionErrors(tmpDGV.CurrentRow))
                    {
                        MessageBox.Show("invalid format.", "Segment Format 
Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        e.Cancel = true;
                    }
                    else
                    {
                        PersistCellErrors(tmpDGV.CurrentRow);
                    }
                }
                tmpDGV.InvalidateRow(e.RowIndex);
            }
            catch (IndexOutOfRangeException ex)
            {
                //filtered row addition will throw this
                tmpDGV.InvalidateRow(e.RowIndex);
            }

If i debug this code and step through it i can see that when i have finished 
editing the new record and hit enter the row validating event handler fires. 
This works fine at first. The row validating event handler then fires a 
second time and this is when the exception is thrown. I can catch the 
exception and it would seem that the row is successfully added to the 
datagridview however I'd like to know what it is that is causing this 
behavior.

Any help would be greatly appreciated as I am stumped on this one!

Thanks.

Imran
Date:Thu, 2 Aug 2007 06:46:04 -0700   Author:  

RE: DataGridView RowValidating IndexOutOfRangeException   
I forgot to mention one thing. 

I have also managed to narrow down the conditions that cause the error and 
it seems to surface if i have a filter set for a particular column value. For 
example if I have a filter set to name = bob and attempt to add a row but 
specify name = bill i will get the IndexOutOfRangeException.
Date:Thu, 2 Aug 2007 06:54:05 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us