468,549 Members | 2,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,549 developers. It's quick & easy.

Trying to understand the DataGridView

I am trying to find the event (if there is one) which occurs when a row
is added to the DataGridView.

The closest I can find is the RowsAdded event which says in documentation:

Occurs after a new row is added to the System.Windows.Forms.DataGridView.

OK then so I debug my code. I am adding 11 rows with a datasource and I
get 4 occurences of the RowsAdded:

?e
{System.Windows.Forms.DataGridViewRowsAddedEventAr gs}
Empty: {System.EventArgs}
RowCount: 1
RowIndex: 0

{System.Windows.Forms.DataGridViewRowsAddedEventAr gs}
Empty: {System.EventArgs}
RowCount: 11
RowIndex: 1

{System.Windows.Forms.DataGridViewRowsAddedEventAr gs}
Empty: {System.EventArgs}
RowCount: 1
RowIndex: 0

{System.Windows.Forms.DataGridViewRowsAddedEventAr gs}
Empty: {System.EventArgs}
RowCount: 11
RowIndex: 1
The call stack shows the same line:

Me.SongInfoBindingSource.DataSource = newSource

for each event occurrence and the above line is executed only once.
This is somewhat confusing as it does not do as the documentation says
and even so why is it doing the event four times and why oh why can the
DataGridView not have events like in ASP.NET so that on each addition of
a row it will give you an event so that you can do whatever is needed at
that time?????

Lloyd Sheen
Aug 20 '08 #1
2 1722
I would use a datasource table for the datagridview. The dataTable
object is much easier to manage for adding/deleting/updating rows.
Everything you do to the underlying dataTable gets displayed instantly
on the datagridview

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Aug 21 '08 #2
I repro the problem here. If you handle also RowsDeleted you'll better
understand what's going on.

Not familiar yet with this but this is where
http://referencesource.microsoft.com/ could be usefull...

For now it looks like rows are added then removed several times ??? I
thought ti could be related to sortable columns but apparently not...

--
Patrice

"Lloyd Sheen" <a@b.ca crit dans le message de groupe de discussion :
ev**************@TK2MSFTNGP04.phx.gbl...
I am trying to find the event (if there is one) which occurs when a row is
added to the DataGridView.

The closest I can find is the RowsAdded event which says in documentation:

Occurs after a new row is added to the System.Windows.Forms.DataGridView.

OK then so I debug my code. I am adding 11 rows with a datasource and I
get 4 occurences of the RowsAdded:

?e
{System.Windows.Forms.DataGridViewRowsAddedEventAr gs}
Empty: {System.EventArgs}
RowCount: 1
RowIndex: 0

{System.Windows.Forms.DataGridViewRowsAddedEventAr gs}
Empty: {System.EventArgs}
RowCount: 11
RowIndex: 1

{System.Windows.Forms.DataGridViewRowsAddedEventAr gs}
Empty: {System.EventArgs}
RowCount: 1
RowIndex: 0

{System.Windows.Forms.DataGridViewRowsAddedEventAr gs}
Empty: {System.EventArgs}
RowCount: 11
RowIndex: 1
The call stack shows the same line:

Me.SongInfoBindingSource.DataSource = newSource

for each event occurrence and the above line is executed only once. This
is somewhat confusing as it does not do as the documentation says and even
so why is it doing the event four times and why oh why can the
DataGridView not have events like in ASP.NET so that on each addition of a
row it will give you an event so that you can do whatever is needed at
that time?????

Lloyd Sheen

Aug 21 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by DraguVaso | last post: by
1 post views Thread by Bruce HS | last post: by
7 posts views Thread by Mitchell S. Honnert | last post: by
7 posts views Thread by =?Utf-8?B?TG9zdEluTUQ=?= | last post: by
3 posts views Thread by Andrus | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.