Hierarchical Data Grid View Delete Row

Posted on -

Join a community of over 2.6m developers to have your questions answered on Hierarchical Data Grid (RadGridView). Select only one nested row at a time. Of UI for Silverlight GridView. Start with our free trials.

  1. Hierarchical Data Grid View Delete Row Map
  2. Hierarchical Data Grid View Delete Row 2017
  3. Hierarchical Data Grid View Delete Rows
-->

Note

The DataGridView control replaces and adds functionality to the DataGrid control; however, the DataGrid control is retained for both backward compatibility and future use, if you choose. For more information, see Differences Between the Windows Forms DataGridView and DataGrid Controls.

The Windows Forms DataGrid control displays data in a series of rows and columns. The simplest case is when the grid is bound to a data source with a single table that contains no relationships. In that case, the data appears in simple rows and columns, as in a spreadsheet. For more information about binding data to other controls, see Data Binding and Windows Forms.

Hierarchical Data Grid View Delete Row Map

If the DataGrid is bound to data with multiple related tables, and if navigation is enabled on the grid, the grid will display expanders in each row. With an expander, the user can move from a parent table to a child table. Clicking a node displays the child table, and clicking a back button displays the original parent table. In this manner, the grid displays the hierarchical relationships between tables.

The following screenshot shows a DataGrid bound to data with multiple tables:

Row

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 Formss TableStyles property.

The following illustration shows the objects included in the DataGrid control:

Table styles and column styles are synchronized with DataTable objects and DataColumn objects by setting their MappingName properties to the appropriate TableName and ColumnName properties. When a DataGridTableStyle that has no column styles is added to a DataGrid control bound to a valid data source, and the MappingName property of that table style is set to a valid TableName property, a collection of DataGridColumnStyle objects is created for that table style. For each DataColumn found in the Columns collection of the DataTable, a corresponding DataGridColumnStyle is added to the GridColumnStylesCollection. GridColumnStylesCollection is accessed through the GridColumnStyles property of the DataGridTableStyle. Columns can be added or deleted from the grid using the Add or Remove method on the GridColumnStylesCollection. For more information, see How to: Add Tables and Columns to the Windows Forms DataGrid Control and How to: Delete or Hide Columns in the Windows Forms DataGrid Control.

A collection of column types extends the DataGridColumnStyle class with rich formatting and editing capabilities. All column types inherit from the DataGridColumnStyle base class. The class that is created depends on the DataType property of the DataColumn from which the DataGridColumn is based. For example, a DataColumn that has its DataType property set to Boolean will be associated with the DataGridBoolColumn. The following table describes each of these column types.

Column TypeDescription
DataGridTextBoxColumnAccepts and displays data as formatted or unformatted strings. Editing capabilities are the same as they are for editing data in a simple TextBox. Inherits from DataGridColumnStyle.
DataGridBoolColumnAccepts and displays true, false, and null values. Inherits from DataGridColumnStyle.

Double-clicking the right edge of a column resizes the column to display its full caption and widest entry.

Table Styles and Column Styles

As soon as you have established the default format of the DataGrid control, you can customize the colors that will be used when certain tables are displayed within the data grid.

This is achieved by creating instances of the DataGridTableStyle class. Table styles specify the formatting of specific tables, distinct from the default formatting of the DataGrid control itself. Each table may have only one table style defined for it at a time.

Sometimes, you will want to have a specific column look different from the rest of the columns of a particular data table. You can create a customized set of column styles by using the GridColumnStyles property.

Column styles are related to columns in a dataset just like table styles are related to data tables. Just as each table may only have one table style defined for it at a time, so too can each column only have one column style defined for it, in a particular table style. This relationship is defined in the column's MappingName property.

If you have created a table style without column styles added to it, Visual Studio will add default column styles when the form and grid are created at run time. However, if you have created a table style and added any column styles to it, Visual Studio will not create any column styles. Also, you will need to define column styles and assign them with the mapping name to have the columns that you want appear in the grid.

Because you specify which columns are included in the data grid by assigning them a column style and no column style has been assigned to the columns, you can include columns of data in the dataset that are not displayed in the grid. However, because the data column is included in the dataset, you can programmatically edit the data that is not displayed.

Note

In general, create column styles and add them to the column styles collection before adding table styles to the table styles collection. When you add an empty table style to the collection, column styles are automatically generated for you. Consequently, an exception will be thrown if you try to add new column styles with duplicate MappingName values to the column styles collection.

Sometimes, you will want to just tweak one column among many columns; for example, the dataset contains 50 columns and you only want 49 of them. In this case, it is easier to import all 50 columns and programmatically remove one, rather than programmatically adding each of the 49 individual columns you want.

Hierarchical Data Grid View Delete Row 2017

Format

Hierarchical Data Grid View Delete Rows

Formatting

Formatting that can be applied to the DataGrid control includes border styles, gridline styles, fonts, caption properties, data alignment, and alternating background colors between rows. For more information, see How to: Format the Windows Forms DataGrid Control.

Events

Besides the common control events such as MouseDown, Enter, and Scroll, the DataGrid control supports events associated with editing and navigation within the grid. The CurrentCell property determines which cell is selected. The CurrentCellChanged event is raised when the user navigates to a new cell. When the user navigates to a new table through parent/child relations, the Navigate event is raised. The BackButtonClick event is raised when the user clicks the back button when the user is viewing a child table, and the ShowParentDetailsButtonClick event is raised when the show/hide parent rows icon is clicked.

See also