VS2500 - How to set 'currently viewed rows' ??

F

frostbb

Greetings:

Working on a VS2005 C# program.

I have a DataGridView control that is bound to dataviews generated by
various database queries. i.e. the user enters search criteria and the
query results end up in the grid. The DataViewGrid is Read Only. The user
has the option of selecting a single record from the grid which causes all
of the associated database record values to become available for edit in an
area outside of the DataViewGrid.

Once the user completes the data updates and saves the data back to the
database I >> refresh << the DataGridView to reflect the updates.

I have figured out how to re-select the DataGridView record that was
updated.

How do I ensure that the selected/updated record is visible in the
DataGridView window after the requery ???

i.e. if the window can display 10 rows and the data set is 30 rows long ...
how to I ensure that row #21 appears in the DataGridView window ??

Thanks in advance.

Barry
in Oregon
 
L

Linda Liu [MSFT]

Hi Oregon,

Based on my understanding, your question is how to ensure a particular
DataGridViewRow to be visible in a DataGridView. If I'm off base, please
feel free to let me know.

You have two options to do this.

One option is to set the DataGridView's CurrentCell property to the first
cell of the specified DataGridViewRow. Once we set a DataGridViewRow as the
current row, this row will scroll into the visible area of the
DataGridView. The following is a sample which sets the 5th DataGridViewRow
as the current row:

this.dataGridView1.CurrentCell = this.dataGridView1.Rows[4].Cells[0]

The other option is to set the DataGridView's
FirstDisplayedScrollingRowIndex property to the row index of the specified
DataGridViewRow. The following is a sample:

this.dataGridView1.FirstDisplayedScrollingRowIndex = 4;

Hope this helps.
If you have any question, 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.
 
B

Bar

Linda,

Thank you for the quick reply and aplogies for the late reply on my
part.

I used your " this.dataGridView1.CurrentCell =
this.dataGridView1.Rows[4].Cells[0]" option and it worked just as I
had hoped. Now when a user updates data derived from a specific
DataGridView row, I can ensure that the updated information appears as
one of the rows in the refreshed DataGridView display window.

Many Thanks !

Barry
in Oregon
 
G

Guest

Linda,

I am using the FirstDisplayedScrollingRowIndex to scroll the view to the
bottom without changing the selected "CurrentCell". If the window is small
before the scroll is called, I get an InvalidOperationException "No room is
available to display rows" event. How can I avoid this error and yet have
the grid scroll to the bottom without changing the current cell?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top