Better DataGridView: Custom Scrollbar, Frozen Columns/Rows, Right-to-Left, Autoscroll

(iGrid.NET Control Tour, Step 6 of 6)

The iGrid.NET control is a better DataGridView control from many points of view. This control tour page highlights some benefits of iGrid if we compare it to WinForms DataGridView and contains more illustrations of our versatile DataGrid/DataGridView alternative.

DataGridView custom scrollbar

Many Internet-forums for .NET developers contain questions like custom scrollbar for datagridview. The source of all these questions is the standard approach to DataGridView scrollbars implementation. In real life, we often need to change the scrollbar width or color, add custom buttons to it, etc:

Better DataGridView: custom scrollbars

Our WinForms grid provides you with properties and methods which allow you to adjust the appearance and behavior of its scrollbars as you like. You can apply a custom color theme to them, disable them, or make them always visible or hidden. It is even possible to make the scrollbars semi-transparent.

Draw your attention to the two square buttons with the plus and minus signs on the vertical scrollbar. These are custom buttons you can add to any scrollbar. You can add as many custom buttons with your own icons as you need and process user clicks on those buttons!

Better DataGridView right-to-left mode

10Tec .NET grid fully supports right-to-left scripts, such as Arabic and Hebrew. When you set the RightToLeft property to True, the grid 'reverses' its interface accordingly:

Right-to-left mode in a better DataGridView, iGrid.NET

The standard DataGridView also has the RightToLeft property which works this way, but what is much more important is that you cannot change the right-to-left direction for one column in DataGridView. In iGrid.NET you can, and you can even force only some cells to display right-to-left text.

Selection modes and unselectable cells

iGrid.NET supports single cell, multiple cells, single row, and multiple rows selections. Multiple cells/rows can be selected with the CTRL key + mouse click, using just mouse click when simple selection mode is on, or by mouse dragging with the left button pressed (so called drag select). The appearance of the selected cells/rows and current cell can be customized with both opaque and semi-transparent colors.

The following picture demonstrates how iGrid.NET marks the new selected area with a semi-transparent color when you move the mouse pointer in multi-selection mode holding down the mouse button:

Better DataGridView multi-selection using drag select

If you need to make a cell unselectable in DataGridView (protect it from being selected using both the keyboard and mouse), there is no a simple solution for this task. In iGrid.NET, you make a cell non-selectable using just one Boolean Selectable property.

Auto-scrolling support

When the user clicks the middle mouse button, iGrid.NET is put into auto-scrolling (or drag-scrolling) mode. Moving the mouse pointer, you can adjust the direction and speed of scrolling:

Auto-scrolling support in a better DataGridView

When you click the middle button, a marker pops up on the screen showing the reference point from which scrolling will occur. The arrows on the marker indicate the possible scrolling directions. This works like in Internet Explorer and MS Office applications.

Sophisticated grid line styles

The grid lines can have different widths, styles (solid, dotted, dashed, etc.), and colors. The GridLines object property allows you to adjust the grid lines used in different parts of iGrid. You can adjust each of the following grid lines independently - the horizontal and vertical grid lines, the extended grid lines, the grid lines for group rows and the grid lines that frame the cells area:

Changing style, color, visibility of grid lines in a better DataGridView

In WinForms DataGridView, the abilities to change grid lines are very limited. First, there is just one property to set the color for all grid lines. Second, if you need to hide the horizontal and/or vertical grid lines in DataGridView, generally you do it by changing the cell border setting (DataGridView.CellBorderStyle). Other grid line features like non-standard styles and extended grid lines aren't supported at all, and you need to use techniques like custom drawing to implement them. In iGrid, you do all these things with the help of one object property.

Frozen rows/columns in DataGridView and iGrid.NET

iGrid.NET allows you to freeze some first rows and columns like DataGridView:

Frozen rows and columns in a better DataGridView

To fix a row in DataGridView, you use the DataGridViewRow.Frozen property. But the main problem with it is that this row is moved if the user sorts the grid, and you need to implement special workarounds - like this based on custom sort. iGrid.NET is free from this problem - you just specify the number of rows/columns to freeze, and all works as expected.

Look carefully at the edge of the frozen area on the picture above. It can be also adjusted like iGrid.NET's grid lines - you can set its color, width and pen style. It's a small but one more useful feature of iGrid which allows us to recommend it as a better DataGridView.

Autofilter add-on for iGrid.NET »