Grid Scroll Bar

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

Is there a way to force a vertical scroll bar on the data grid, even if the
data grid has no rows?

Thanks

Regards
 
Yes, but as far as I know you need to do it all yourself. So if you plan on
reusing this sometime you can always just derive from the DataGrid and wire
in the logic yourself. You may need to make a few modifications to the code
below, but this should get you started.

public class MyDataGrid : System.Windows.Forms.DataGrid
{
public MyDataGrid ()
{
this.VertScrollBar.Visible = true;
this.VertScrollBar.VisibleChanged += new
EventHandler(VertScrollBar_VisibleChanged);
}

private void VertScrollBar_VisibleChanged(object sender, EventArgs e)
{
this.VertScrollBar.Visible = true;
}

protected override void OnResize(System.EventArgs e)
{
// TODO: Need to take caption height and some other aspects into
consideration.
this.VertScrollBar.Bounds = new Rectangle(this.ClientRectangle.Width -
this.VertScrollBar.Width, 0, this.VertScrollBar.Width,
this.ClientRectangle.Height);
base.OnResize(e);
}
}
 
This is C#, but shouldn't matter. I fully expect that this would run in a
VB.Net application (if translated, of course). And this could also be
written as a control in C# and then used in a VB.Net app - it's the beauty
of IL code.
 
This is a vb group and I am getting c# examples. :( as if vb.net wasn't
difficult enough.

Regards
 
Impressive. I used the converter and tried out your code. It works very
well.
 
Instantiate this at Form class level and remember to add it to the
form.controls collection

me.controls.add( InstantiatedGrid )


Public Class MyDataGrid
Inherits System.Windows.Forms.DataGrid

Public Sub New()
Me.VertScrollBar.Visible = True
AddHandler Me.VertScrollBar.VisibleChanged, AddressOf
VertScrollBar_VisibleChanged
End Sub 'New


Private Sub VertScrollBar_VisibleChanged(sender As Object, e As
EventArgs)
Me.VertScrollBar.Visible = True
End Sub 'VertScrollBar_VisibleChanged


Protected Overrides Sub OnResize(e As System.EventArgs)
' TODO: Need to take caption height and some other aspects into
consideration.__unknown
Me.VertScrollBar.Bounds = New Rectangle(Me.ClientRectangle.Width -
Me.VertScrollBar.Width, 0, Me.VertScrollBar.Width,
Me.ClientRectangle.Height) '
'ToDo: Error processing original source shown below
'
'
'-----^--- Syntax error: 'identifier' expected
MyBase.OnResize(e)
End Sub 'OnResize
End Class 'MyDataGrid
"
 
Back
Top