Page 272 - Open Soource Technologies 304.indd
P. 272
Event Driven Programming
12.3.1.7 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 portion
of the text in the cell.
In the Visual Basic 2005 DataGridView control, these properties no longer exist. The cells in the
DataGridView control are based on the TextBox control; by adding code to the
EditingControlShowing event handler you can access the SelectionLength, SelectionStart, and
SelectedText properties of the underlying control.
12.3.1.8 Split Views
The Visual Basic 6.0 DataGrid control supports a split view, allowing the user to display the same
data side-by-side. The Split object and the Split, Splits, and TabAcrossSplits properties control
the ability to display a split view.
In the Visual Basic 2005 DataGridView control, these properties no longer exist. However, you
can achieve the same effect using one or more SplitContainer controls and multiple DataGridView
controls. To duplicate the functionality of the TabAcrossSplits property, you can use the
StandardTab property of the DataGridView control.
12.3.2 Code Changes for the DataGrid Control
The following code demonstrates the differences between Visual Basic 6.0 and Visual Basic 2005
by showing how, in each version, to highlight the text in a cell when a user selects the cell in
a DataGridView control.
‘ Visual Basic 6.0
Private Sub DataGrid1_Click()
DataGrid1.SelStart = 1
DataGrid1.SelLength = DataGrid1.Text
MsgBox(“The selected text is “ & DataGrid1.SelText)End Sub
‘ Visual Basic 2005
Private Sub DataGridView1_EditingControlShowing( _
ByVal sender As Object, ByVal e As System.Windows.Forms. _
DataGridViewEditingControlShowingEventArgs) _
Handles DataGridView1.EditingControlShowing
CType(e.Control, TextBox).SelectionStart = 0
CType(e.Control, TextBox).SelectionLength = Len(CType(e.Control, _
TextBox).Text)
MsgBox(“The selected text is “ & CType(e.Control, _
TextBox).SelectedText)
End Sub]
266 LOVELY PROFESSIONAL UNIVERSITY