DataGrid Control for Visual Basic 6
-
Upload
claresse-kawaii -
Category
Documents
-
view
367 -
download
2
Transcript of DataGrid Control for Visual Basic 6
1/3/12 DataGrid Control for Visual Basic 6.0 Users
1/10msdn.microsoft.com/en-us/library/y4ddh1ac(v=vs.80).aspx
DataGrid Control for Visual Basic 6.0 Users Visual Studio 2005
The DataGrid control in Visual Basic 6.0 is replaced by the Windows Forms DataGridView control inVisual Basic 2005. The names of some properties, methods, events, and constants are different,and in some cases there are differences in behavior.
Conceptual Differences
Data Binding
The Visual Basic 2005 DataGridView control does not need data-specific methods or eventsbecause all actions are performed through the data source. Because of this separation ofpresentation and data functionality, the data source can be changed with or without user interfaceinput. Also, multiple controls bound to the same data source will always stay in sync.
Navigation
Properties for viewing and navigation in the DataGrid control (such as TabAction, EnterAction,AllowArrows, WrapCellPointer, and Scrollable) are no longer needed. For example, the gridfunctions as though the Scrollable property is set to True: If more data exists than can bedisplayed, a scroll bar appears automatically. Excel-style navigation through the grid is the default,allowing the user to move forward with the TAB key and backward with the SHIFT+TAB keycombination. For more information, see Default Keyboard and Mouse Handling in the Windows FormsDataGridView Control.
Caption Property
In Visual Basic 6.0, the Caption property is used to display a title bar above the grid; if theCaption property is left empty, no title bar is displayed.
The Visual Basic 2005 DataGridView control does not support a title bar. However, you canachieve the same effect using a Label control.
Data Formatting
In Visual Basic 6.0, formatting data in the DataGrid control is handled using the DataFormatproperty and a StdDataFormat object. Formatting is applied on a column-by-column basis.
In the Visual Basic 2005 DataGridView control, formatting is accomplished using the Formatproperty of a DataGridViewCellStyle object. Formatting can be applied to individual cells, columns,or rows. For more information, see Data Formatting in the Windows Forms DataGridView Control.
hWndEditor Property
In Visual Basic 6.0, the hWndEditor property is used to pass the window handle assigned to aDataGrid control's editing window to a Windows API call.
The Visual Basic 2005 DataGridView control does not have a separate window handle when in editmode; instead, use the Handle property of the DataGridView control or any embedded editcontrols.
MarqueeStyle Property
In Visual Basic 6.0, the MarqueeStyle property controls the appearance of a selected cell or rowby changing the border style, inverting the foreground and background colors, or invoking an editwindow.
1/3/12 DataGrid Control for Visual Basic 6.0 Users
2/10msdn.microsoft.com/en-us/library/y4ddh1ac(v=vs.80).aspx
There is no direct equivalent for the Visual Basic 2005 DataGridView control. However, you canachieve the same effect through a combination of the SelectionMode, CellBorderStyle, and Formatproperties. For more information, see Selection Modes in the Windows Forms DataGridView Control.
SelLength, SelStart, SelText Properties
In the Visual Basic 6.0 DataGrid control, when a cell enters edit mode, the SelLength, SelStart,and SelText properties can be used to set the initial position of the caret or to highlight a portionof the text in the cell.
In the Visual Basic 2005 DataGridView control, these properties no longer exist. The cells in theDataGridView control are based on the TextBox control; by adding code to theEditingControlShowing event handler you can access the SelectionLength, SelectionStart, andSelectedText properties of the underlying control.
Split Views
The Visual Basic 6.0 DataGrid control supports a split view, allowing the user to display the samedata side-by-side. The Split object and the Split, Splits, and TabAcrossSplits properties controlthe ability to display a split view.
In the Visual Basic 2005 DataGridView control, these properties no longer exist. However, you canachieve the same effect using one or more SplitContainer controls and multiple DataGridViewcontrols. To duplicate the functionality of the TabAcrossSplits property, you can use theStandardTab property of the DataGridView control.
Code Changes for the DataGrid Control
The following code demonstrates the differences between Visual Basic 6.0 and Visual Basic 2005 byshowing how, in each version, to highlight the text in a cell when a user selects the cell in aDataGridView control.
' V i s u a l B a s i c 6 . 0P r i v a t e S u b D a t a G r i d 1 _ C l i c k ( ) D a t a G r i d 1 . S e l S t a r t = 1 D a t a G r i d 1 . S e l L e n g t h = D a t a G r i d 1 . T e x t M s g B o x ( " T h e s e l e c t e d t e x t i s " & D a t a G r i d 1 . S e l T e x t )E n d S u b
' V i s u a l B a s i c 2 0 0 5P r i v a t e S u b D a t a G r i d V i e w 1 _ E d i t i n g C o n t r o l S h o w i n g ( _B y V a l s e n d e r A s O b j e c t , B y V a l e A s S y s t e m . W i n d o w s . F o r m s . _D a t a G r i d V i e w E d i t i n g C o n t r o l S h o w i n g E v e n t A r g s ) _H a n d l e s D a t a G r i d V i e w 1 . E d i t i n g C o n t r o l S h o w i n g C T y p e ( e . C o n t r o l , T e x t B o x ) . S e l e c t i o n S t a r t = 0 C T y p e ( e . C o n t r o l , T e x t B o x ) . S e l e c t i o n L e n g t h = L e n ( C T y p e ( e . C o n t r o l , _ T e x t B o x ) . T e x t ) M s g B o x ( " T h e s e l e c t e d t e x t i s " & C T y p e ( e . C o n t r o l , _ T e x t B o x ) . S e l e c t e d T e x t )E n d S u b
VB
1/3/12 DataGrid Control for Visual Basic 6.0 Users
3/10msdn.microsoft.com/en-us/library/y4ddh1ac(v=vs.80).aspx
Note
DataGrid Control Property, Method, and Event Equivalencies
The following tables list Visual Basic 6.0 properties, methods, and events, along with their VisualBasic 2005 equivalents. Those properties, methods, and events that have the same name andbehavior are not listed. All Visual Basic 2005 enumerations map to the System.Windows.Formsnamespace unless otherwise noted.
This table provides links to topics explaining behavior differences. Where there is no directequivalent in Visual Basic 2005, links are provided to topics that present alternatives.
Properties
Visual Basic 6.0 Visual Basic 2005 Equivalent
AddNewMode New implementation. Data operations are handled in the data source. For
more information, see Displaying Data in the Windows Forms DataGridView
Control.
Align Dock and Anchor
AllowAddNew AllowNew (BindingSource)
AllowArrows No longer an adjustable property; arrow navigation always allowed. For
more information, see Default Keyboard and Mouse Handling in the Windows
Forms DataGridView Control.
AllowDelete AllowRemove (BindingSource)
AllowRowSizing AllowUserToResizeRows
AllowUpdate AllowEdit (BindingSource)
Appearance New implementation. For more information, see Appearance and BorderStyle
Properties for Visual Basic 6.0 Users.
ApproxCount New implementation. Data operations are handled in the data source. For
more information, see Displaying Data in the Windows Forms DataGridView
Control.
BackColor BackgroundColor
Colors are handled differently in Visual Basic 2005. For more information,
see Color Behavior for Visual Basic 6.0 Users.
Bookmark New implementation. You can now directly access any item.
Caption New implementation. Use a Label control to simulate a title bar.
1/3/12 DataGrid Control for Visual Basic 6.0 Users
4/10msdn.microsoft.com/en-us/library/y4ddh1ac(v=vs.80).aspx
Note
Note
Note
Note
Col SelectedColumns
ColumnHeaders ColumnHeadersVisible
Container Parent; inherited from Control.
CurrentCellModified IsCurrentCellDirty, IsCurrentCellInEditMode
CurrentCellVisible CurrentCell
If the CurrentCell property is set to a cell that is not visible, the grid
scrolls to show that cell (similar to setting CurrentCellVisible = True).
DataChanged IsCurrentCellDirty, IsCurrentRowDirty
DataFormats DataGridViewCellStyle.object.
Formatting can be set for an individual cell, column, or row.
DefColWidth Width DataGridViewColumn object.
DragIcon
DragMode
New implementation. For more information, see Drag and Drop for Visual
Basic 6.0 Users.
EditActive IsCurrentCellInEditMode
FirstRow FirstDisplayedScrollingRowIndex
Font
FontBold
FontItalic
FontName
FontSize
FontStrikethrough
FontUnderline
Font
Fonts are handled differently in Visual Basic 2005. For more information,
see Font Handling for Visual Basic 6.0 Users.
ForeColor ForeColor
1/3/12 DataGrid Control for Visual Basic 6.0 Users
5/10msdn.microsoft.com/en-us/library/y4ddh1ac(v=vs.80).aspx
Note
Note
Note
Colors are handled differently in Visual Basic 2005. For more information,
see Color Behavior for Visual Basic 6.0 Users.
HeadFont DataGridViewCellStyle object.
Fonts are handled differently in Visual Basic 2005. For more information,
see Font Object for Visual Basic 6.0 Users.
HeadLines No direct equivalent. Use the WrapMode property of the
DataGridViewCellStyle object in combination with ColumnHeadersHeight.
Height Height, inherited from Control class.
Coordinates are handled differently in Visual Basic 2005. For more
information, see Coordinate System for Visual Basic 6.0 Users.
HelpContextID New implementation. For more information, see Help Support for Visual
Basic 6.0 Users.
hWnd Handle
hWndEditor New implementation. Use Handle.
Index New implementation. For more information, see Control Arrays for Visual
Basic 6.0 Users.
Left Left, inherited from Control class.
Coordinates are handled differently in Visual Basic 2005. For more
information, see Coordinate System for Visual Basic 6.0 Users.
LeftCol FirstDisplayedScrollingColumnIndex
MarqueeStyle No direct equivalent. Use the SelectionMode, CellBorderStyle, and
Format properties.
RecordSelectors RowHeadersVisible
Row SelectedRows
1/3/12 DataGrid Control for Visual Basic 6.0 Users
6/10msdn.microsoft.com/en-us/library/y4ddh1ac(v=vs.80).aspx
Note
Note
RowDividerStyle GridColor, CellBorderStyle, RowHeadersBorderStyle,
ColumnHeadersBorderStyle properties.
RowHeight Height
SelBookmarks New implementation. You can now directly access any item.
SelEndCol
SelStartCol
SelectedCells, SelectedColumns
SelLength No direct equivalent. Use the SelectionLength property in the
EditingControlShowing event handler.
SelStart No direct equivalent. Use the SelectionStart property in the
EditingControlShowing event handler.
SelText No direct equivalent. Use the SelectedText property in the
EditingControlShowing event handler.
Split
Splits
TabAcrossSplits
New implementation. Split views are not directly supported; use a
SplitContainer control.
TabAction StandardTab
Tag New implementation.
Text CurrentCell.Value
The Value property returns an Object; use CStr or ToString to
convert it to a String.
ToolTipText ToolTip component
For more information, see ToolTip Support for Visual Basic 6.0 Users.
Top Top
Coordinates are handled differently in Visual Basic 2005. For more
information, see Coordinate System for Visual Basic 6.0 Users.
VisibleCols DisplayedColumnCount method.
1/3/12 DataGrid Control for Visual Basic 6.0 Users
7/10msdn.microsoft.com/en-us/library/y4ddh1ac(v=vs.80).aspx
Note
Note
Note
Methods
Visual Basic 6.0 Visual Basic 2005 Equivalent
In Visual Basic 6.0, partially visible columns are always included in the
count; the DisplayedColumnCount method uses a Boolean
includePartialColumns parameter to determine whether partially
visible columns are included.
VisibleRows DisplayedRowCount method.
In Visual Basic 6.0, partially visible rows are always included in the
count; the DisplayedRowCount method uses a Boolean
includePartialRows parameter to determine whether partially visible
rows are included.
WhatsThisHelpID New implementation. For more information, see Help Support for Visual
Basic 6.0 Users.
Width Width, inherited from Control class.
Coordinates are handled differently in Visual Basic 2005. For more
information, see Coordinate System for Visual Basic 6.0 Users.
WrapCellPointer No longer an adjustable property; default behavior is WrapCellPointer =
True.
CaptureImage New implementation. Capturing the contents of a DataGridView control to a
PictureBox control is not supported.
ClearFields New implementation. Column formatting is automatic when re-binding.
ClearSelCols ClearSelection
ColContaining IndexOf (DataGridViewColumnCollection)
Drag New implementation. For more information, see Drag and Drop for Visual Basic
6.0 Users..
GetBookmark New implementation. Bookmarks are no longer supported.
1/3/12 DataGrid Control for Visual Basic 6.0 Users
8/10msdn.microsoft.com/en-us/library/y4ddh1ac(v=vs.80).aspx
Note
Events
Visual Basic 6.0 Visual Basic 2005 Equivalent
HoldFields New implementation. Column formatting is preserved when rebinding.
Move SetBounds, inherited from Control class.
Coordinates are handled differently in Visual Basic 2005. For more
information, seeCoordinate System for Visual Basic 6.0 Users.
Rebind ResetBindings, inherited from Control class.
RowBookmark New implementation. Bookmarks are no longer supported.
RowContaining IndexOf (DataGridViewColumnCollection)
RowTop GetContentBounds (DataGridViewCell)
Scroll New implementation method. Use the CurrentCell property.
SetFocus Focus
ShowWhatsThis New implementation. For more information, see Help Support for Visual Basic 6.0
Users.
SplitContaining New implementation. Split views are not directly supported; use a
SplitContainer control.
ZOrder BringToFront()or SendToBack()functions
AfterColEdit CellEndEdit
AfterColUpdate
AfterDelete
New implementation. Data operations are handled in the data source. For
more information, see Displaying Data in the Windows Forms DataGridView
Control.
AfterUpdate RowsAdded
BeforeColEdit CellBeginEdit
BeforeColUpdate
BeforeDelete
BeforeInsert
BeforeUpdate
New implementation. Data operations are handled in the data source. For
more information, see Displaying Data in the Windows Forms DataGridView
Control.
1/3/12 DataGrid Control for Visual Basic 6.0 Users
9/10msdn.microsoft.com/en-us/library/y4ddh1ac(v=vs.80).aspx
Note
ButtonClick Click (Button control)
Change TextChanged
The behavior of the TextChanged event is slightly different. For more
information, see ComboBox Control Change Event for Visual Basic 6.0
Users.
Click SelectedIndexChanged
ColEdit CellBeginEdit
ColResize ColumnWidthChanged
DblClick CellMouseDoubleClick
DragDrop
DragOver
New implementation. For more information, see Drag and Drop for Visual Basic
6.0 Users.
Error DataError
HeadClick ColumnHeaderMouseClick
MouseDown CellMouseDown
MouseMove CellMouseMove
MouseUp CellMouseUp
OLECompleteDrag
OLEDragDrop
OLEDragOver
OLEGiveFeedback
OLESetData
OLEStartDrag
New implementation. For more information, see Drag and Drop for Visual Basic
6.0 Users.
OnAddNew RowsAdded
RowColChange CurrentCellChanged
1/3/12 DataGrid Control for Visual Basic 6.0 Users
10/10msdn.microsoft.com/en-us/library/y4ddh1ac(v=vs.80).aspx
© 2012 Microsoft. All rights reserved.
Upgrade Notes
When a Visual Basic 6.0 project is upgraded to Visual Basic 2005, the Change event of theDataGrid control is mapped to the TextChanged event of the Visual Basic 2005 DataGridViewcontrol. The behavior of the TextChanged event differs from that of the Change event; thisdifference may cause unintended results in your code.
Any code related to data-specific methods or events is not upgraded. Warning comments are addedto the code, and the code must be removed or modified before compiling the application.
See Also
Reference
DataGridView Control Overview (Windows Forms)Controls and Programmable Objects Compared in Different Languages and Libraries
Concepts
DataGridView Control Technology Summary (Windows Forms)What's New in Windows Forms and Windows Forms Controls
Other Resources
DataGridView Control (Windows Forms)Windows Forms Controls for Visual Basic 6.0 UsersWindows Forms Data Binding
Community Content
RowResize RowHeightChanged
SelChange SelectionChanged
SplitChange New implementation. Split views are not directly supported; use a
SplitContainer control.
Validate Validating