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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Scott LysleRank #49 · 31K reputationPosted Mar 10, 2007, 5:51 PM EST
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();
}
}
}
}