always show the scrollbar in a datagridview
how can you do this? ... let's say that the datagridview has a big size and it only displays two records...i still want the scrollbar to appear regarless of the amount of records...how can i do this?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Scott LyslePosted Mar 10, 2007, 10:51 PM
Here is the code modified to work with the DataGridView (this is the entire class, there is nothing else): Just use this control instead of the standard DataGridView.
using
System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace
junk{ public partial class CustomDgv : DataGridView
{ private const int CAPTIONHEIGHT = 21;
private const int BORDERWIDTH = 2; public CustomDgv()
{
InitializeComponent();
// make scrollbar visible & add handler
VerticalScrollBar.Visible = true;
VerticalScrollBar.VisibleChanged += new EventHandler(ShowScrollBars);
} private void ShowScrollBars( object sender, EventArgs e )
{
if (!VerticalScrollBar.Visible)
{
int width = VerticalScrollBar.Width;
VerticalScrollBar.Location =
new Point( ClientRectangle.Width - width - BORDERWIDTH, CAPTIONHEIGHT );
VerticalScrollBar.Size =
new Size( width, ClientRectangle.Height - CAPTIONHEIGHT - BORDERWIDTH );
VerticalScrollBar.Show();
}
}
}
}