Panel中的DataGridView无法滚动

时间:2013-10-17 13:18:13

标签: c# winforms datagridview scroll panel

在更新\ work时,我需要在DataGridView上有一个流畅优雅的滚动。

因为每次我更新我的DataGridView,它都会将Scrollbar重置为顶部。 我找到了使用FirstDisplayedScrollingRowIndex属性的解决方案,但后来我意识到仅仅保存RowIndex是不够的,我需要将注意力集中在滚动上。我尝试谷歌它,发现我需要使用Panel。

我试过,但我不知道如何将我的DGV绑定到Panel。 我把它移到Panel中。在代码this.panel1.Controls.Add(this.DGV);中添加 并将DGV.ScrollBars转为none。 而且我在面板上看不到任何滚动条,在DGV中滚动数据。

我试过的解决方案:

Scrollbar loses focus when datagridview refreshs its content

Problem with DataGridView and scroll position

How can I set the position of my datagrid scrollbar in my winforms app?

1 个答案:

答案 0 :(得分:0)

"I need to have a smooth elegant scroll on my DataGridView while it is updating\work".

VirtualizationStackPanel / VirtualizationPanel将有助于根据滚动量加载数据网格中的项目。

http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.aspx http://msdn.microsoft.com/en-IN/library/system.windows.controls.virtualizingpanel(v=vs.90).aspx

still i don't see any scrolls on my panel, to scroll data in DGV

DGV.ScrollBarsnone将禁用网格滚动条。您可以尝试在ScrollViewer

之外插入Panel控件

http://msdn.microsoft.com/en-us/library/ms750665.aspx