Set the scrollbar width of a DataGridView

I am working on a mobile device application and would like to make the datagrid scroll button larger to improve the usability of the touch screen. I do not want to change the display properties of the system settings windows, as this will affect the device as a whole.

Is there an easy way to change the scrollbar width in a datagrid view?

+2
source share
2 answers

I think you have to turn off yourself. Do not worry, it should not be so difficult. I say should not, because it has been a while since I did .NET CF UI (shooting from the hips), but implemented a special scroller for the .NET 2.0 touch screen user interface.

So here is what you need to do:

  • Hide scroll bars in grid view
  • Create a custom control in which two buttons are located: one top, bottom.
  • Handle the clicks on these buttons and redirect them by scrolling up / down calls in the grid.

This is an easy way. You don't get drag and drop stuff, but it is rarely used in such a tiny user interface. You can also add later if you want.

Warning. ScrollUp / Down APIs may not display in the grid view. In this case, you need to overlay your own control over the grid view, which will show the scroll bars. You hide the built-in scrollbars with a custom control and instead of calling ScrollUp / Down, you send Windows messages to the area located behind your custom control for fake clicks and getting a grid to navigate the way you like.

Hm. I assumed the .NET Compact Framework, since you mentioned it for a mobile device ... Is it CF? If not, everything should be a little easier.

EDIT

A basic sample of customizable grid scrolling is here!

+1
source
FieldInfo fi = dataGridView1.GetType().GetField( "m_sbVert", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance ); ( ( VScrollBar ) fi.GetValue( dataGridView1 ) ).Width = 50; fi = ultraGrid1.GetType().GetField( "m_sbHorz", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance ); ( ( HScrollBar ) fi.GetValue( ultraGrid1 ) ).Height = 0; 

Where 50 is the width of the vertical scrollbar and 0 is the height of the horizontal scrollbar.

 using System.Reflection; 

everything is at the beginning of your form.

Works for WinCE 5.0 .

+1
source

Source: https://habr.com/ru/post/1334203/


All Articles