请教怎么让DataGridView一直显示垂直滚动条
1个回答
展开全部
试一试这个,不过好像有点问题:
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"
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"
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询