Hiding HScroll in DataGrid

  • Thread starter Thread starter PeterB
  • Start date Start date
P

PeterB

Hello!

I am trying to force a datagrid not to show the Horizontal Scroll. From what
I have seen it is not possible to do this in an easy manner (i.e. set a
property etc.).

I tried this using Reflection and FieldInfo to set the HScroll.Visible
property to false in the DataGrid paint event.but there are a some unwanted
side-effects.

1. The area behind the HScroll is not updated (How would you reapaint that
area?)
2. The VScroll heigth has to be set to datagrid size each time. (easy)
3. Each Paint event first draws the HScroll and then it is removed with my
code. Not pretty!

Another idea would be to create a custom DataGrid. I could override the
OnPaint event. But even so, base.OnPaint() would draw the HScroll first and
the unwanted flicker would appear. Overriding OnPaint totally (without
calling base) sounds like a major task...

Has anyone been involved in something similar?

/ Peter
 
The recommendation is to set the width of the various columns in the data
grid so that they are not wider than the width of the datagrid-the width of
the scroll bar. Then you simply need to prevent the datagrid from allowing
the end user from resizing the columns. That can be done by deriving a class
from Datagrid and overriding the OnMouseDown event. If the mouse event
occurs in the column headers, don't call base.OnMouseDown, otherwise do call
base.OnMouseDown.

HTH,
Mark.
 
Back
Top