请问如何让DataGridView一直显示垂直滚动条
由于自动产生的垂直滚动条占用空间后产生水平滚动条,而预留垂直滚动条的位置又产生一段空白,想问下能不能让垂直滚动条一直存在,即使datagridview没有内容或只有一行内容。
------解决方案--------------------
mark.
------解决方案--------------------
试一试这个,不过好像有点问题:
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"
------解决方案--------------------
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"
呵呵,都这样了,还说啥呢~