What is the difference between Datagrid and DataGridview in VB.Net ?
What is the difference between Datagrid and DataGridview in VB.Net ?
The DataGridView control is a new control that replaces the DataGrid control. The DataGridView control provides numerous basic and advanced features that are missing in the DataGrid control. Additionally, the architecture of the DataGridView control makes it much easier to extend and customize than the DataGrid control.
The DataGrid control is retained for backward compatibility and for special needs. For nearly all purposes, you should use the DataGridView control. The only feature that is available in the DataGrid control that is not available in the DataGridView control is the hierarchical display of information from two related tables in a single control. You must use two DataGridView controls to display information from two tables that are in a master/detail relationship.
Following are some features available in the DataGridView control that are missing from the DataGrid control.
Multiple column types The DataGridView control provides more built-in column types than the DataGrid control. These column types meet the needs of most common scenarios, but are also easier to extend or replace than the column types in the DataGrid control.
Multiple ways to display data The DataGrid control is limited to displaying data from an external data source. The DataGridView control, however, can display unbound data stored in the control, data from a bound data source, or bound and unbound data together.
Multiple ways to customize the display of data
Multiple options for changing cell, row, column, and header appearance and behavior
Code to use Datagrid view control in VB.Net.
Code:Private Sub AddDataGridColumn() Dim dataset As New DataSet ' Put some actions to populate the dataset Dim TblStyle As New DataGridTableStyle With TblStyle ' Set column style With .GridColumnStyles ' Set datagrid ComboBox ColumnStyle for PubID field .Add(New DataGridComboBoxColumn(dataset.Tables.Item("Companies"), 1, 0)) With .Item(0) .MappingName = "PubID" .HeaderText = "Company ID" .Width = 150 .NullText = String.Empty End With End With End With ' Add TableStyle DataGrid1.TableStyles.Add(TblStyle) End Sub
Bookmarks