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

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

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

DataGridView custom scrollbar

Many Internet forums contain questions from developers asking about 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 allowing 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 mode and right-to-left scripts - such as Arabic, Persian, or Hebrew. When you enable right-to-left mode with the RightToLeft property, the grid 'reverses' its interface accordingly:

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

The standard DataGridView also has the RightToLeft property working this way. However, you cannot set right-to-left direction for one column in DataGridView. You can do this in iGrid.NET, and you can even force only some cells to display right-to-left text.

Selection modes and non-selectable cells

iGrid.NET supports single and multiple cell selection modes, the same for rows if row mode is on. 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 the current cell can be customized by setting to opaque or 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 non-selectable in DataGridView (protect it from being selected using both the keyboard and mouse), there is no simple solution. In iGrid.NET, you make a cell non-selectable with just one Selectable property.

Auto-scroll support in DataGridView

If you click the middle mouse button when the mouse pointer is inside iGrid.NET, auto-scroll mode is activated (also known as drag-scroll). A special marker pops up on the screen showing the reference point from which scrolling will occur, and now you can scroll the grid by moving the mouse pointer:

Auto-scrolling support in a better DataGridView

The arrows on the marker indicate the possible scrolling directions. The speed of scrolling is related to the distance of the mouse pointer from the scroll origin. This works exactly like in Microsoft Office applications.

Unfortunately, Microsoft did not make auto-scroll a built-in feature of DataGridView. To implement auto-scroll on middle-click in DataGridView, you should code this yourself. Here is an example of how to harness the Reader Mode from Windows API for this:

Enabling Reader Mode on the DataGridView (middle-click auto-scroll)

In contrast to DataGridView, auto-scroll is a built-in feature of iGrid.NET and you get it out-of-the-box with no coding.

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 can make all these things with GridLines 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 freeze a row in DataGridView, you use the DataGridViewRow.Frozen property. The main problem with it is that the frozen row is moved if the user sorts the grid. To avoid this, you must implement a special workarounds like this one 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.

The edge of the frozen area can be also adjusted like grid lines in iGrid.NET. You can set color, width, and pen style separately for the edges separating frozen rows and columns from non-frozen ones. This is a one more useful feature of iGrid that allows us to recommend it as a better DataGridView.

iGrid.NET compatibility info »