请教怎么让DataGridView一直显示垂直滚动条

 我来答
xiangjuan314
2016-05-09 · TA获得超过3.3万个赞
知道大有可为答主
回答量:2.9万
采纳率:0%
帮助的人:2889万
展开全部
试一试这个,不过好像有点问题:
public class CustomDataGridView : DataGridView
{

/// <summary>
/// Constructor
/// </summary>
public CustomDataGridView (): base()
{
VerticalScrollBar.Visible = true;
VerticalScrollBar.VisibleChanged += new EventHandler(VerticalScrollBar_VisibleChanged);
}

void VerticalScrollBar_VisibleChanged(object sender, EventArgs e)
{
if (!VerticalScrollBar.Visible)
{
int width = VerticalScrollBar.Width;
VerticalScrollBar.Location =
new Point(ClientRectangle.Width -width, 1);

VerticalScrollBar.Size =
new Size(width, ClientRectangle.Height - 1 - this.HorizontalScrollBar.Height);
VerticalScrollBar.Show();
}

}

}

问题是:
This works fine in all senarios, but if Horizontal scrollbar is needed( i.e. if column width is greater than control width), last column is displayed behind the Vertical scroll bar. Is there any way to accomplish diaplying the scrollbar properly.

让后别人回答用这种方式:
Try to create a user control with both horizontal and vertical scroll bars. Put a DataGridView inside the user control and disable the DataGridView control to have scrollbars.

When you scroll your user control, set DataGridView.FirstDisplayedScrollingRowIndex property and DataGridView.FirstDisplayedScrollingColumnIndex property to update the DataGridView’s content manually.

Since you are the author of the user control, you can choose when to display both two scrollbars, either one of them or neither.

这个回答的人更牛:)
No - this is not something that the DataGridView supports. Your alternative is to always hide the vertical scrollbar and use a VerticalScrollBar control to the right of the grid and manually hook up the scroll events for the scrollbar and the DGV.

-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式