Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Represents a column in a DataGridView control.
The DataGridViewColumn class represents a logical column in a DataGridView control. You can retrieve columns through the Columns collection of the control.
Unlike a DataGridViewRow, which contains the actual collection of cells in a DataGridView, DataGridViewColumn is used mainly to adjust the appearance and behavior of the column user interface (UI), such as column width and cell style.
Types that derive from DataGridViewColumn typically initialize the CellTemplate property to a new instance of a related type derived from the DataGridViewCell class. Any column properties that relate to the appearance or behavior of individual cells are wrappers for the corresponding properties of the template cell. Changing one of these properties on the column automatically changes the value on the cell template and on all cells in the column. To override the specified value for individual cells, set the cell values after you set the column value.
For a full list of properties, methods and events see the API documentation.
Represents a column of cells that contain MaskedTextBox controls in a DataGridView.
The MaskedTextBoxColumn class is a specialized type of the DataGridViewColumn class used to logically host cells that display MaskedTextBox controls. A MaskedTextBoxColumn has an associated DataGridViewMaskedTextBoxCell in every DataGridViewRow that intersects it. Each cell contains a MaskedTextBox control.
You can populate the cells manually by setting their Value properties. Alternatively, you can bind the column to the data source indicated by the DataGridView.DataSource property. If the DataGridView is bound to a database table, set the column DataPropertyName property to the name of a column in the table. If the DataGridView is bound to a collection of objects, set the DataPropertyName property to the name of an object property.
For a full list of properties, methods and events see the API documentation.
The MaskedTextBox's Mask property features a popup dialog to quickly select one of the common predefined masks.
Represents a data grid control.
The DataGridView control provides a customizable table for displaying data. The DataGridView class allows customization of cells, rows, columns, and borders through the use of properties such as DefaultCellStyle, ColumnHeadersDefaultCellStyle, CellBorderStyle, and GridColor.
You can use a DataGridView control to display data with or without an underlying data source. Without specifying a data source, you can create columns and rows that contain data and add them directly to the DataGridView using the Rows and Columns properties. You can also use the Rows collection to access DataGridViewRow objects and the DataGridViewRow.Cells property to read or write cell values directly.
As an alternative to populating the control manually, you can set the DataSource and DataMember properties to bind the DataGridView to a data source and automatically populate it with data.
When working with very large amounts of data, you can set the VirtualMode property to true
to display a subset of the available data. Virtual mode requires the implementation of a data cache from which the DataGridView control is populated.
For a full list of properties, methods and events see the API documentation.
Populate the DataGridView control without binding them to a data source by using the Append and Fill methods.
AutoSizeColumnsMode and AutoSizeRowsMode let you configure the control so that column widths and row heights are automatically adjusted either to fill the control or to fit cell contents. Size adjustments occur in fill mode whenever the width of the control changes. In content-based sizing modes, size adjustments occur whenever cell contents change or, if WrapMode is enabled, whenever row heights change. Some content-based sizing modes let you limit the size adjustment to the currently displayed rows in order to increase performance.
To change the sizing mode for an individual column, set its AutoSizeMode property. The default value of this property is NotSet
, indicating that the column inherits its behavior and its InheritedAutoSizeMode property value from the control.
Don't confuse the AutoSize property with the rows and columns autosizing. If you set The AutoSize property of the DataGridView to true, it will cause the grid to grow horizontally and/or vertically (depending on the layout settings) to fit all the coulumns and all the rows.
The DataGridView control supports the standard Windows Forms data binding model, so it can bind to a variety of data sources. Usually, you bind to a BindingSource that manages the interaction with the data source. The BindingSource can be any Windows Forms data source, which gives you great flexibility when choosing or modifying your data's location.
To connect a DataGridView control to data:
Implement a method to handle the details of retrieving the data.
In the form's Load event handler, bind the DataGridView control to the BindingSource, and call the appropriate method to retrieve the data.
Columns are automatically generated when AutoGenerateColumns is set to true
and the DataSource or DataMember properties are set or changed. Columns can also be automatically generated when the AutoGenerateColumns property is changed from false
to true
. If this property is true
and the DataSource changes so there are columns that do not match the columns of the previous DataSource value, data in the unmatched columns is discarded. This property is ignored if the DataSource or DataMember properties are not set.
When AutoGenerateColumns is set to true
, the DataGridView control generates one column for each public property of the objects in the data source. If the bound objects implement the ICustomTypeDescriptor interface, the control generates one column for each property returned by the GetProperties method. Each column header will contain the value of the property name the column represents.
The DataGridView control supporting providing user-defined data management operations.
Virtual mode is designed for use with very large stores of data. When the VirtualMode property is true
, you create a DataGridView with a set number of rows and columns and then handle the CellValueNeeded event to populate the cells. Virtual mode requires implementation of an underlying data cache to handle the population, editing, and deletion of DataGridView cells based on actions of the user.
Use the DataGridView.DataRead event to build and maintain your server-side cache or data retrieval code that collects the data to feed the CellValueNeeded event.
The DataGridView control is probably the largest and most complex control and widget in Wisej.NET. It exposes dozens of events, properties and methods and supports a large set of complex and advanced features.
Usually when an application needs to extend a control, in this case the DataGridView control, with additional features like a status bar, or paging strip, or other "connected" controls, the approach is to create a UserControl, drop a DataGridView in it and add all the additional controls around it in order to create a cool custom grid.
This approach, however, "hides" the DataGridView in a UserControl (or another container) and may require a large number of wrapper properties, events and methods to expose the DataGridView features to the code that uses the new custom control.
A really powerful feature of the DataGridView in Wisej.NET is the ability to also behave as a container. You can drag and drop (or add programmatically) any control inside the DataGridView and it will adapts its "inside" configuration to incorporate the additional controls - it is a composed DataGridView.
You can do that directly in the container using the composed grid, or you can create a custom control extending the DataGridView and dropping controls in there.
Control the layout using Docking and BringToFront or SendToBack. You can also set the ResizableEdges property of the inner controls and implement a simple splitting system where ethe user can resize the inner controls.
When the built-in cell editors are not sufficient, or you need to customize the editing of any cell, you can assign a custom editing control to DataGridViewColumn.Editor and Wisej will use that instance of the control to edit the content of the cells in that column.
Unless the editing control fires the TextChanged event when edited, it's up to your code to handle the CellBeginEdit and CellEndEdit events and update the value of the cell.
When the custom cell editors, or the HTML content, or the cell painting are not enough, the DataGridView support placing any control in any cell, even spanning multiple cells!
"With great power come great responsibility".
Use this feature responsibly, adding a control on every cell will, well, add a control to every cell and if your grid has 10,000 rows you will end up having 10,000 controls and slow down the browser and use up memory on the server.
When you really need to display something too complex for HTML, or you have an existing painting routine in .NET, the DataGridView allows you to paint directly into the cell.
Attach a handler to DataGridView.CellPaint and enable user painting on the cell by setting the UserPaint property to true:
Setting the AllowHtml property of a DataGridViewColumn or a specific DataGridViewCell allows the cell to display HTML text in the browser. This feature allows you to display just about anything in cell: images, progress bars, charts, multiple data, etc.
Another way to display custom HTML in a cell without having to store HTML in the cell value is to use the CellFormatting event. It allows you to "render" the display of the cell:
You can detect clicks inside a particular element inside a cell by setting the "role" attribute of the HTML element and check the e.Role string that comes with the cell click events.
Item | Description |
---|---|
Class name
wisej.web.DataGrid
Theme appearance
"table" is the entire widget. All components of the grid use the "table-[name]" appearance key. See Themes.
Child components
See JavaScript.
ToolContainer state
"datagrid", see Embedded Tools.
Source code
Hosts a collection of DataGridViewButtonCell objects.
The DataGridViewButtonColumn class is a specialized type of the DataGridViewColumn class used to logically host cells that respond to simple user input. A DataGridViewButtonColumn has an associated DataGridViewButtonCell in every DataGridViewRow that intersects it. Each cell supplies a user interface (UI) that is similar to a Button control.
To display the same button text for every cell, set the UseColumnTextForButtonValue property to true
and set the Text property to the desired button text.
The default sort mode for this column type is NotSortable
.
To respond to user button clicks, handle the DataGridView.CellClick or DataGridView.CellContentClick event. In the event handler, you can use the DataGridViewCellEventArgs.ColumnIndex property to determine whether the click occurred in the button column. You can use the DataGridViewCellEventArgs.RowIndex property to determine whether the click occurred in a button cell and not on the column header.
For a full list of properties, methods and events see the API documentation.
Represents a column of cells that contain DateTimePicker controls in a DataGridView.
The DateTimePickerColumn class is a specialized type of the DataGridViewColumn class used to logically host cells that display DateTimePicker controls. A DateTimePickerColumn has an associated DataGridViewDateTimePickerCell in every DataGridViewRow that intersects it. Each cell contains a DateTimePicker control.
You can populate the cells manually by setting their Value properties. Alternatively, you can bind the column to the data source indicated by the DataGridView.DataSource property. If the DataGridView is bound to a database table, set the column DataPropertyName property to the name of a column in the table. If the DataGridView is bound to a collection of objects, set the DataPropertyName property to the name of an object property.
For a full list of properties, methods and events see the API documentation.
Represents a column of cells that contain links in a DataGridView control.
The DataGridViewLinkColumn class is a specialized type of the DataGridViewColumn class used to logically host cells that respond to user clicks. The DataGridViewLinkColumn class is similar to the DataGridViewButtonColumn class but provides a different user experience that may be more appropriate in certain situations, such as displaying a URL stored in a database table.
To display the same link text for every cell, set the UseColumnTextForLinkValue property to true
and set the Text property to the desired link text.
A DataGridViewLinkColumn has an associated DataGridViewLinkCell in every DataGridViewRow that intersects it.
The default sort mode for this column type is NotSortable
.
To respond to user link clicks, handle the DataGridView.CellMouseClick event. You can also use the DataGridView.CellClick event to respond to clicks anywhere in the cell.
For a full list of properties, methods and events see the API documentation.
Hosts a collection of DataGridViewTextBoxCell cells.
The DataGridViewTextBoxColumn class is a specialized type of DataGridViewColumn class used to logically host cells that enable displaying and editing of text strings. A DataGridViewTextBoxColumn has an associated DataGridViewTextBoxCell object in every DataGridViewRow that intersects it. When a DataGridViewTextBoxCell becomes activated, it supplies a DataGridViewTextBoxEditingControl control to handle user input.
The sort mode for this column type defaults to Automatic
.
For a full list of properties, methods and events see the API documentation.
Hosts a collection of DataGridViewImageCell objects.
The DataGridViewImageColumn class is a specialized type of the DataGridViewColumn class used to logically host cells that display images. A DataGridViewImageColumn has an associated DataGridViewImageCell in every DataGridViewRow that intersects it. Each cell is capable of containing an Image or an Icon.
By default, empty cells display a default error graphic. To prevent this graphic from appearing for cell values equal to null
or DBNull.Value
, set the DataGridViewCellStyle.NullValue property of the cell style object returned by the DefaultCellStyle property to null
before adding rows to the control. This does not affect the row for new records, however. To prevent the error graphic from appearing in the row for new records when the control AllowUserToAddRows property value is true
, you must also either explicitly set the cell value to null
in a handler for the control RowsAdded event or set the column CellTemplate property to an instance of a DataGridViewImageCell-derived type with an overridden DefaultNewRowValue property that returns null
.
The default sort mode for this column type is NotSortable
.
For a full list of properties, methods and events see the API documentation.
Represents a column of cells that contain NumericUpDown controls in a DataGridView.
The DataGridViewNumericUpDownColumn class is a specialized type of the DataGridViewColumn class used to logically host cells that display NumericUpDown controls. A DataGridViewNumericUpDownColumn has an associated DataGridViewNumericUpDownCell in every DataGridViewRow that intersects it. Each cell contains a NumericUpDown control.
You can populate the cells manually by setting their Value properties. Alternatively, you can bind the column to the data source indicated by the DataGridView.DataSource property. If the DataGridView is bound to a database table, set the column DataPropertyName property to the name of a column in the table. If the DataGridView is bound to a collection of objects, set the DataPropertyName property to the name of an object property.
For a full list of properties, methods and events see the API documentation.
Hosts a collection of DataGridViewCheckBoxCell objects.
The DataGridViewCheckBoxColumn class is a specialized type of the DataGridViewColumn class used to logically host cells that indicate binary state. A DataGridViewCheckBoxColumn has an associated DataGridViewCheckBoxCell in every DataGridViewRow that intersects it. Each cell supplies a user interface (UI) that is similar to a CheckBox control.
The default sort mode for this column type is NotSortable
.
Typically, check box cell values are intended either for storage, like any other data, or for performing bulk operations. If you want to respond immediately when users click a check box cell, you can handle the DataGridView.CellContentClick event, but this event occurs before the cell value is updated. If you need the new value at the time of the click, one option is to calculate what the expected value will be based on the current value. Another approach is to commit the change immediately, and handle the DataGridView.CellValueChanged event to respond to it.
For a full list of properties, methods and events see the .
The ThreeState property defines whether the checkbox cells will allow three check states or the default two check states.
The DataGridViewCheckBoxColumn can also be sorted according to the cells value in ascending or descending order:
Represents a column of DataGridViewComboBoxCell objects.
The DataGridViewComboBoxColumn class is a specialized type of DataGridViewColumn used to logically host cells that enable users to select values from a list of choices. A DataGridViewComboBoxColumn has an associated DataGridViewComboBoxCell in every DataGridViewRow that intersects it.
You can populate the cells manually by setting their Value properties. Alternatively, you can bind the column to the data source indicated by the DataGridView.DataSource property. If the DataGridView is bound to a database table, set the column DataPropertyName property to the name of a column in the table. If the DataGridView is bound to a collection of objects, set the DataPropertyName property to the name of an object property.
You can populate the column drop-down list manually by adding values to the Items collection. Alternatively, you can bind the drop-down list to its own data source by setting the column DataSource property. If the values are objects in a collection or records in a database table, you must also set the DisplayMember and ValueMember properties. The DisplayMember property indicates which object property or database column provides the values that are displayed in the drop-down list. The ValueMember property indicates which object property or database column is used to set the cell Value property.
For a full list of properties, methods and events see the API documentation.
The DataGridViewComboBoxColumn features several different drop down presets:
Simple: The list is always visible and that the text portion is editable. The user can enter a new value or can select an existing value in the list.
DropDown: The list is displayed by clicking the down arrow, or pressing either the Down, Alt+Down or Alt+Up keys, and that the text portion is editable. The user can enter a new value or select an existing value in the list.
DropDownList: The list is displayed by clicking the down arrow, or pressing either the Down, Alt+Down or Alt+Up keys, and that the text portion is not editable. The user cannot enter a new value and can only select a value already in the list.