473,473 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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. I have managed to narrow down the conditions that cause
the error and it seems to surface if i have a filter set for a paricular
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.

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
Aug 2 '07 #1
0 2934

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

Similar topics

0
by: DraguVaso | last post by:
Hi, I'm using the DataGridView in VB.NET 2.0. The DataSource is a Generic List of a custom class0: lstMyPersonnes = New List(Of clsPersonne). When I add a new clsPersonne to lstMyPersonnes,...
9
by: Matt | last post by:
In many places in my application, I have a DataGridView which users can either enter data into or use as a method of navigation in a master/detail form view. I need a method of stopping the user...
0
by: Dave | last post by:
I have a datagridview and I am using the RowValidated and RowValidating events for each row in the datagridview. However, when doing some testing of the datagridview, I noticed that if I click in...
0
by: bob | last post by:
Hi all, I'm having a hard time figuring out the ORDER that the events in the DataGridView control fire in, and also determining exactly WHEN each event fires. The documentation seems to have...
0
by: Webbert | last post by:
I have a custom collection that implements IBindingList. When I click/tab onto a new row, the IBindingList.AddNew() method fires and adds a new item into the collection. At this point, if I...
2
by: Dinis Correia | last post by:
Hi all, How do I prevent row change in a Datagridview? Is there something like a BeforeCurrentRowChanged with an eventarg that could prevent from changing current row? I'm using datagridview...
0
by: JoZ CaVaLLo | last post by:
Hi. I need to know all events that can be generated in a datagridview. In particularly I'd like to find a list describing the dependencies of each event. In Exemple: first there is a...
11
by: dave18 | last post by:
Hello all! I found a solution to my original question, but there's still so much I don't understand about it, I thought I'd give this forum a try. At the very least, maybe it will help someone...
1
by: Faelenor | last post by:
Hi, I have a DataGridView bounded to a database table. I'm trying to validate a row entered by a user with the RowValidating event. What i want to do is check if the user entered a value already...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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...
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.