DataGridView 列拖放和自动水平滚动
任何人都可以建议我应该如何在 DataGridView 中实现列拖放(带自动滚动)功能。我知道我可以使用控件的AllowUserToDragDrop 选项。但是,由于我的 datagridview 控件具有相对较多的列,因此我需要一个跟随当前拖放位置的自动滚动功能,以便用户可以在拖放之前看到目标列。我已经实现了自定义拖放功能,但在启用自动滚动选项时仍然遇到问题。
Can anyone please suggest how should I implement column drag and drop (with auto scroll) feature in DataGridView. I know I can use the controll's AllowUserToDragDrop option. However, since my datagridview control has relatively large number of columns, I need an auto scroll feature which follows the current drag-drop position so that users can see the destination column(s) before dropping. I have implemented the custom drag and drop feature but still I am having problem to enable auto scroll option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在使用以下类自动滚动 TTreeView。 TScroller 是在它所在的 Frame 的 Create 中创建的,并传入 TreeView。它在框架的销毁中被销毁。在 TreeView 的 OnDragOver 中,我只需调用 MyDragScroller.Scroll(State);
笔记:
如果您有更多需要自动滚动的控件,则需要为每个控件创建一个 TScroller。在这种情况下,使用某种观察者/被观察机制在所有滚动控件之间共享计时器可能会对应用程序的性能带来很大好处。
I am using the following class to auto-scroll a TTreeView. The TScroller is created in the Create of the Frame on which it sits, passing in the TreeView. It is destroyed in the frame's Destroy. In the OnDragOver of the TreeView I simply call MyDragScroller.Scroll(State);
Notes:
If you have more controls that need auto-scrolling, you would need to create a TScroller per control. In that case it would probably do the performance of your app a lot of good to use some sort of observer/observed mechanism to share a timer between all scrolling controls.
您可以处理 OnMouseMove,并以编程方式相应地滚动。
You could handle OnMouseMove, and programatically scroll accordingly.