Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / December 2006

Tip: Looking for answers? Try searching our database.

DataGridView row change event?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bradley Plett - 04 Dec 2006 21:44 GMT
There seems to be an event for pretty much everything in the
DataGridView, including events that I can't imagine ever needing.
However, there doesn't seem to be a good event for a row change (i.e.
when the user's selection changes from one row to another).  Am I
missing something?  This seems like a simple and obvious one, but I
certainly haven't found a really good one yet.  I have a second (think
parent-child) grid that I want filtered by the selection in the parent
row grid.  I've tried the "RowEnter" event, and it seems to work, but
it also seems to get fired far too often, especially at startup and
shutdown.  Any ideas?  How are others doing this kind of thing?

Thanks!
Brad.
Bradley Plett - 04 Dec 2006 22:19 GMT
P.S.  I just discovered that "RowEnter" isn't the best choice either,
since when it is called, CurrentRow still reflects the previous
choice, not the new row.  So, now I'm even more anxious for a good
answer to this.  It's probably something trivial I'm overlooking,
but....

Thanks!
Brad.

>There seems to be an event for pretty much everything in the
>DataGridView, including events that I can't imagine ever needing.
[quoted text clipped - 9 lines]
>Thanks!
>Brad.
Linda Liu [MSFT] - 05 Dec 2006 04:00 GMT
Hi Brad,

The symbol of the completion of row navigation is the CurrentRow property
of the DataGridView is changed. Unfortunately, DataGridView doesn't provide
such a CurrentRowChanged event.  

Since the CurrentRow property of the DataGridView refers the row containing
the current cell and DataGridView provides CurrentCellChanged event, we
could make use of the CurrentCellChanged event to inform of the completion
of row navigation.

Yes, you are right. When you navigate through the rows in a DataGridView,
the RowEnter and RowLeave events occur before the CurrentCellChanged event.
So these two events aren't appropriate to use in this case.

BTW, the CurrentCellChanged event will be raised when changing cells within
a row, which is not really what you want.

To solve this problem, I think you could add a variable in your program
indicating the index of the last current row. When the CurrentCellChanged
event rises, you may check whether the value of  
this.DataGridView1.CurrentCell.RowIndex is equal to the value of the
variable.

If the result is Yes, don't call the code for the extra processing.
Otherwise, set the value of the variable to the lastest value of
CurrentCell.RowIndex and call the code to do extral processing.

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Bradley Plett - 05 Dec 2006 07:22 GMT
Thanks!  It's not quite the answer I was looking for, but....

I'd actually resorted to using the CurrentCellChanged event already,
but as you mention, it's not perfect.  Still, it will do for my
purpose for now.

Brad.

>Hi Brad,
>
[quoted text clipped - 50 lines]
>
>This posting is provided "AS IS" with no warranties, and confers no rights.
Kevin Spencer - 05 Dec 2006 13:53 GMT
If you are using a BindingSource, you can use an event handler for the
BindingSource.PositionChanged event.

Signature

HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

There is a madness to my method.

> Thanks!  It's not quite the answer I was looking for, but....
>
[quoted text clipped - 63 lines]
>>This posting is provided "AS IS" with no warranties, and confers no
>>rights.
RobinS - 04 Dec 2006 22:23 GMT
Are you using data binding? If so, you can bind the child grid
to the relation with the parent grid, and when you change
rows in the parent, the children will change automatically.
Do you want to know how to do that?

Robin S.
----------------------------
> There seems to be an event for pretty much everything in the
> DataGridView, including events that I can't imagine ever needing.
[quoted text clipped - 9 lines]
> Thanks!
> Brad.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.