Click here to Skip to main content
15,886,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys,

I have a application that is going to be used as a public display screen, to update the public about the process that are ongoing. The application connects to sql database and just pretty much relays information back. The application will self-update against the Database. The application shouldn’t need to be touched once installed. So no need to press down the scroll bar, in fact the scroll bars shouldn't be visible.

The number of rows could change, as there is another separate application that operators can update information in the database. So the number of rows could be anything from 20 to 100 or even more but my public screen (I am using a datagridview to display data) should only display 20 rows at a time. what I need to do is figure out a way if there are more than 20 rows in datagrid for the Grid to auto scroll downwards (smoothly) while freezing the header row and not to jump from one row to the next and maybe back up or to start from the top again. Just like in this article: Scrolling a Rich/Textbox Automatically[^]

Another method could also be used as long as the scrolling is smooth. I am using windows forms, but a WPF solution is also welcome. Database is SQL.

Pretty much the system needs to cycle from top to bottom of the list slowly and smoothly pausing at the top. Most solutions I have found jump straight to the bottom row.

I have no idea if this is possible so thought I would ask?
Thank you very much for any kind assistance.

What I have tried:

I tried to use datagridview current selected index than increment it by one, but this clearly is not my desired solution.
I saw in the forum some suggestions to increment datagridview FirstDisplayedScrollingRowIndex, but here also it will luck the smoothness.
Some suggested to use a panel and scroll that panel, How can that be achieved?
Posted
Updated 18-Oct-16 10:11am

C#
private static void EnsureVisibleRow(DataGridView view, int rowToShow)
{
    if (rowToShow >= 0 && rowToShow < view.RowCount)
    {
        var countVisible = view.DisplayedRowCount(false);
        var firstVisible = view.FirstDisplayedScrollingRowIndex;
        if (rowToShow < firstVisible)
        {
            view.FirstDisplayedScrollingRowIndex = rowToShow;
        }
        else if (rowToShow >= firstVisible + countVisible)
        {
            view.FirstDisplayedScrollingRowIndex = rowToShow - countVisible + 1;
        }
    }
}


However, keep in mind when you do this, that adding new rows and trying to keep the last row added visible will interfere with the user's ability to navigate the control.

I think you might be better off showing the last item added as a separate textbox or something along that line.
 
Share this answer
 
The datagridview will only be refreshed to add new data after it has scrolled from top to last row then back to top.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900