开发者

Windows Forms DataGridView Scrolling

I'm looking to create a kind of sliding scroll effect in a DataGridView. I want to scroll down one row, but I want it to slide slowly so that it's clear to the user that it's being scrolled.

Is this somehow possible? I've found that you can scroll directly to a row by using the FirstDisplayedScrollingRowIndex property, but that's not quite what I want.

EDIT: I figure I can accomplish this if I could find a way to scroll between row boundaries. I could then programmatically scroll several times in small increments to make it appear as if it's scrolling slo开发者_如何学JAVAwly.

Help would be much appreciated.


So I found a solution that works, although it's not a great one. The following code gives the appearance of smooth scrolling in a DataGridView.

    //Insert Row at bottom of DataGridView with a row height of 0 here

    DataGridView1.Enabled = false;

    for (int i = 0; i < ROW_HEIGHT; i++)
    {
        DataGridView1.Rows[0].Height--;
        DataGridView1.Rows[LAST_ROW].Height++;
        Thread.Sleep(20);
    }

    DataGridView1.Enabled = true;

    // Remove first row in DataGridView here

This solution works only because I am removing the very first row in the DataGridView each time a new one is added, which is why I can slowly reduce it to height 0, since it's getting removed anyway. This basically gives me a fixed amount of rows, essentially creating a fixed size queue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜