Grid control for windows forms




















Binding data to the DataGridView control is straightforward and intuitive, and in many cases it is as simple as setting the DataSource property. When you bind to a data source that contains multiple lists or tables, set the DataMember property to a string that specifies the list or table to bind to. The DataGridView control supports the standard Windows Forms data binding model, so it will bind to instances of classes described in the following list:.

Any class that implements the IList interface, including one-dimensional arrays. The DataGridView control supports data binding to the public properties of the objects returned by these interfaces or to the properties collection returned by an ICustomTypeDescriptor interface, if implemented on the returned objects. Typically, you will bind to a BindingSource component and bind the BindingSource component to another data source or populate it with business objects.

The BindingSource component is the preferred data source because it can bind to a wide variety of data sources and can resolve many data binding issues automatically. For more information, see BindingSource Component. The DataGridView control can also be used in unbound mode, with no underlying data store. The DataGridView control is highly configurable and extensible, and it provides many properties, methods, and events to customize its appearance and behavior.

In this manner, the grid displays the hierarchical relationships between tables. The DataGrid can provide a user interface for a dataset, navigation between related tables, and rich formatting and editing capabilities.

The display and manipulation of data are separate functions: The control handles the user interface, whereas data updates are handled by the Windows Forms data-binding architecture and by.

NET Framework data providers. Therefore, multiple controls bound to the same data source will stay in sync. If you are familiar with the DataGrid control in Visual Basic 6. When the grid is bound to a DataSet , the columns and rows are automatically created, formatted, and filled. For more information, see Data Binding and Windows Forms. Following the generation of the DataGrid control, you can add, delete, rearrange, and format columns and rows depending on your needs.

For the DataGrid control to work, it should be bound to a data source using the DataSource and DataMember properties at design time or the SetDataBinding method at run time. The DataGrid control shows the results of actions that are performed on the data. Most data-specific actions are not performed through the DataGrid , but instead through the data source. If the data in the bound dataset is updated through any mechanism, the DataGrid control reflects the changes.

If the data grid and its table styles and column styles have the ReadOnly property set to false , the data in the dataset can be updated through the DataGrid control. Only one table can be shown in the DataGrid at a time. If a parent-child relationship is defined between tables, the user can move between the related tables to select the table to be displayed in the DataGrid control.

Valid data sources for the DataGrid include:. DataTable class. DataView class. DataSet class. DataViewManager class. If your source is a dataset, the dataset might be an object in the form or an object passed to the form by an XML Web service. You can bind to either typed or untyped datasets. You can also bind a DataGrid control to additional structures if the objects in the structure, such as the elements in an array, expose public properties.

The grid will display all the public properties of the elements in the structure. For example, if you bind the DataGrid control to an array of customer objects, the grid will display all the public properties of those customer objects. In some instances, this means that although you can bind to the structure, the resulting bound structure might not have practical application.

For example, you can bind to an array of integers, but because the Integer data type does not support a public property, the grid cannot display any data. Any component that implements the IList interface.

This includes single-dimension arrays. Any component that implements the IListSource interface. Any component that implements the IBindingList interface. A common use of the DataGrid control is to display a single table of data from a dataset. However, the control can also be used to display multiple tables, including related tables.

The display of the grid is adjusted automatically according to the data source. The following methods are need to be override in the derived GridControl for Optimized Vertical scrolling,. It will return true while displaying the scrollbars otherwise return false. The grid can be scroll to the horizontal and vertical direction by tracking the thumbs of the scrollbar.

The grid will scroll the grid contents when leaving the thumb track. To update the contents of the grid when tracking the thumbs, set the VerticalThumbTrack and HorizontalThumbTrack value as true.

To scroll the contents of the grid to the particular cell, use the ScrollCellInView method. This method is used to get the given cell or range of cells into the view. The default value is set to false. The scroll tips text can be changed by setting the ScrollTipFormat property value as of follows,. The scrolling behavior of the current cell moves within the frozen range using the arrow keys can be set by enabling the ScrollFrozen property.

The default value is set to true. The first row index of the view layout can be get by using the TopRowIndex property. It will be varied while scrolling the grid. At any time this will return the first row index of the view layout.

Similarly, the top row index can be changed or scrolled into view by setting TopRowIndex property. The contents of the grid can be automatically scrolled by setting the EnableIntelliMouse property to true. By default the thumbs are used the visible row and column index to update the positions on the Scrollbars. In this case the thumb size of the vertical scrollbar is set based on the overall row count of the grid.

By enabling the UseOldHiddenScrollLogic static property, the hidden columns is not taken to the account for scrolling.

Therefore the scrollbar thumb will draw based only on the visible rows. Vertical scrollbar thumb size changed according to the overall row count without using the hidden scroll logic is shows as follows,. The columns and rows of the GridControl can be scrolled horizontally and vertically using built-in scrollbars. The appearance of the scrollbar can be applied using GridOfficeScrollbars property.

The default scrollbar is OfficeScrollBars. The following are the different styles of scrollbars available for GridControl,. The themes can be applied for the office scrollbars by setting the appropriate color scheme. Following are the color schemes available for the GridControl. Scrollbars have the default context menu strip for setting the scrolling options.

It will popup when right click on the scrollbar. The grid will scroll the contents based on the options selected in the context menu. The scrollbar context menu can be disabled by handling the ShowContextMenu event of the GridControl as follows,.



0コメント

  • 1000 / 1000