SftTree/DLL 7.5 - Tree Control
SftBox/OCX 5.0 - Combo Box Control
SftButton/OCX 3.0 - Button Control
SftMask/OCX 7.0 - Masked Edit Control
SftTabs/OCX 6.5 - Tab Control (VB6 only)
SftTree/OCX 7.5 - Tree Control
SftPrintPreview/DLL 2.0 - Print Preview Control (discontinued)
SftTree/DLL 7.5 - Tree Control
SftBox/OCX 5.0 - Combo Box Control
SftButton/OCX 3.0 - Button Control
SftDirectory 3.5 - File/Folder Control (discontinued)
SftMask/OCX 7.0 - Masked Edit Control
SftOptions 1.0 - Registry/INI Control (discontinued)
SftPrintPreview/OCX 1.0 - Print Preview Control (discontinued)
SftTabs/OCX 6.5 - Tab Control (VB6 only)
SftTree/OCX 7.5 - Tree Control
SftTabs/NET 6.0 - Tab Control (discontinued)
SftTree/NET 2.0 - Tree Control
This sample illustrates cell editing using edit controls and combo boxes, cell navigation, uneditable cells, checkbox cell image.
The source code is located at C:\Program Files (x86)\Softelvdm\SftTree OCX 7.5\Samples\Visual Studio - VB.NET\CellEditing\Form1.vb or C:\Program Files\Softelvdm\SftTree OCX 7.5\Samples\Visual Studio - VB.NET\CellEditing\Form1.vb (on 32-bit Windows versions).
Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click
Application.Exit()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ItemIndex As Integer
ItemIndex = AxSftTree1.Items.Add("Click on a cell to edit")
AxSftTree1.get_Cell(ItemIndex, 1).Text = "Use Tab/Return keys"
AxSftTree1.get_Cell(ItemIndex, 2).Text = "Use arrow keys"
ItemIndex = AxSftTree1.Items.Add("This sample supports cell navigation")
AxSftTree1.get_Cell(ItemIndex, 1).Text = "Ctrl+Home and Ctrl+End"
Dim i As Integer
Dim Item As SftTreeItem
Dim Cell As SftTreeCell
For i = 1 To 50
ItemIndex = AxSftTree1.Items.Add("An item")
AxSftTree1.get_Cell(ItemIndex, 1).Text = "2nd Column"
AxSftTree1.get_Cell(ItemIndex, 2).Text = "3rd Column"
ItemIndex = AxSftTree1.Items.Add("Another item")
Item = AxSftTree1.get_Item(ItemIndex)
Item.Level = 1
Item.Cell(1).Text = "2nd Column"
Item.Cell(2).Text = "3rd Column"
ItemIndex = AxSftTree1.Items.Add("This item can't be edited")
Item = AxSftTree1.get_Item(ItemIndex)
Item.Level = 2
Item.EditIgnore = True
Item.Cell(0).Image.Appearance = SftPictureImageConstants.sftImageCheckboxYes
Item.Cell(1).Text = "2nd Column (can't edit this item)"
Item.Cell(2).Text = "3rd Column (can't edit this item)"
ItemIndex = AxSftTree1.Items.Add("A fourth item")
Item = AxSftTree1.get_Item(ItemIndex)
Item.Level = 1
Cell = AxSftTree1.get_Cell(ItemIndex, 1)
Cell.Text = "This cell can't be edited"
Cell.EditIgnore = True
Cell.Image.Appearance = SftPictureImageConstants.sftImageCheckboxYes
AxSftTree1.get_Cell(ItemIndex, 2).Text = "3rd Column"
Next
AxSftTree1.ColumnsObj.MakeOptimal()
AxSftTree1.RowHeaders.MakeOptimal()
AxSftTree1.Items.RecalcHorizontalExtent()
End Sub
Private Sub AxSftTree1_ItemClick(ByVal sender As Object, ByVal e As AxSftTreeLib75._DSftTreeEvents_ItemClickEvent) Handles AxSftTree1.ItemClick
Dim Img As SftPictureObject
Dim AreaType As SftTreeAreaTypeConstants
AreaType = e.areaType
If AreaType = SftTreeAreaTypeConstants.constSftTreeCellText Then
' User clicked on a cell
AxSftTree1.get_Cell(e.itemIndex, e.colIndex).Edit(0, 0)
ElseIf AreaType = SftTreeAreaTypeConstants.constSftTreeCellGraphic Then
' check if check box - toggle
Img = AxSftTree1.get_Cell(e.itemIndex, e.colIndex).Image
If Img.Appearance = SftPictureImageConstants.sftImageCheckboxNo Then
Img.Appearance = SftPictureImageConstants.sftImageCheckboxYes
ElseIf Img.Appearance = SftPictureImageConstants.sftImageCheckboxYes Then
Img.Appearance = SftPictureImageConstants.sftImageCheckboxNo
End If
End If
End Sub
Private Sub AxSftTree1_ItemDblClick(ByVal sender As Object, ByVal e As AxSftTreeLib75._DSftTreeEvents_ItemDblClickEvent) Handles AxSftTree1.ItemDblClick
Dim Img As SftPictureObject
Dim AreaType As SftTreeAreaTypeConstants
AreaType = e.areaType
If AreaType = SftTreeAreaTypeConstants.constSftTreeCellText Then
' User clicked on a cell
AxSftTree1.get_Cell(e.itemIndex, e.colIndex).Edit(0, 0)
ElseIf AreaType = SftTreeAreaTypeConstants.constSftTreeCellGraphic Then
' check if check box - toggle
Img = AxSftTree1.get_Cell(e.itemIndex, e.colIndex).Image
If Img.Appearance = SftPictureImageConstants.sftImageCheckboxNo Then
Img.Appearance = SftPictureImageConstants.sftImageCheckboxYes
ElseIf Img.Appearance = SftPictureImageConstants.sftImageCheckboxYes Then
Img.Appearance = SftPictureImageConstants.sftImageCheckboxNo
End If
End If
End Sub
Private Sub AxSftTree1_ToolTipVScroll(ByVal sender As Object, ByVal e As AxSftTreeLib75._DSftTreeEvents_ToolTipVScrollEvent) Handles AxSftTree1.ToolTipVScroll
e.text = "Item " & e.itemIndex & " - " & e.text
End Sub
Private Sub AxSftTree1_EditAllowed(ByVal sender As Object, ByVal e As AxSftTreeLib75._DSftTreeEvents_EditAllowedEvent) Handles AxSftTree1.EditAllowed
' Last chance to suppress cell editing for a cell
'If e.itemIndex = 1 And e.colIndex = 1 Then
' e.allowed = False
'End If
End Sub
Private Sub AxSftTree1_EditInitializing(ByVal sender As Object, ByVal e As AxSftTreeLib75._DSftTreeEvents_EditInitializingEvent) Handles AxSftTree1.EditInitializing
Dim ctrl As System.Windows.Forms.Control
' Choose a control based on current column being edited
If e.editCol = 1 Then
ctrl = Combo1
Else
ctrl = Text1
End If
' LeftPix/TopPix/WidthPix/HeightPix describes the current cell area
' we need to return the position and size needed for editing.
' In this example, we use the height of the control on the form
' and center it over the cell.
e.topPix = e.topPix + (e.heightPix - ctrl.Height) / 2
e.heightPix = ctrl.Height
' Set the text in the control used for cell editing and
' set other control-specific properties
If ctrl Is Text1 Then
Text1.Width = 200
Text1.Text = AxSftTree1.get_Cell(e.editIndex, e.editCol).Text
Text1.SelectionStart = 0
Text1.SelectionLength = 999
Else
Combo1.Items.Clear()
Combo1.Items.Add("Option 1")
Combo1.Items.Add("Option 2")
Combo1.Items.Add("Option 3")
Combo1.Items.Add(AxSftTree1.get_Cell(e.editIndex, e.editCol).Text)
Combo1.Text = AxSftTree1.get_Cell(e.editIndex, e.editCol).Text
End If
' Return the control's window handle
e.window = ctrl.Handle.ToInt32()
e.vData = ctrl
' Define navigation keys
' VK_TAB
AxSftTree1.CellEditIntercept(9, SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeChar Or SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeControlChar Or SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeShiftChar)
' VK_RETURN
AxSftTree1.CellEditIntercept(13, SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeChar Or SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeControlChar Or SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeShiftChar)
' VK_HOME
AxSftTree1.CellEditIntercept(36, SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeControlChar)
' VK_END
AxSftTree1.CellEditIntercept(35, SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeControlChar)
If ctrl Is Text1 Then
' We want these keys just for the edit control.
' VK_UP
AxSftTree1.CellEditIntercept(38, SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeChar Or SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeControlChar Or SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeShiftChar)
' VK_DOWN
AxSftTree1.CellEditIntercept(40, SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeChar Or SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeControlChar Or SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeShiftChar)
End If
End Sub
Private Sub AxSftTree1_EditInitialized(ByVal sender As Object, ByVal e As AxSftTreeLib75._DSftTreeEvents_EditInitializedEvent) Handles AxSftTree1.EditInitialized
' Show the combo box dropdown portion
If e.vData Is Combo1 Then
' We're taking over positioning, so we can drop down the dropdown portion of the control
e.positioned = True
Combo1.Left = e.leftPix
Combo1.Top = e.topPix
Combo1.Width = e.widthPix
Combo1.Height = e.heightPix
Combo1.Enabled = True
Combo1.Visible = True
Combo1.Focus()
Combo1.DroppedDown = True
End If
End Sub
Private Sub AxSftTree1_EditNavigating(ByVal sender As Object, ByVal e As AxSftTreeLib75._DSftTreeEvents_EditNavigatingEvent) Handles AxSftTree1.EditNavigating
' Process key pressed
AxSftTree1.EditNavigate(e.key, e.shift)
End Sub
Private Sub AxSftTree1_EditValidate(ByVal sender As Object, ByVal e As AxSftTreeLib75._DSftTreeEvents_EditValidateEvent) Handles AxSftTree1.EditValidate
' Validate the new cell contents
Dim S As String
If e.vData Is Text1 Then
S = Text1.Text
Else
S = Combo1.Text
End If
S = S.Trim()
If S.Length <= 0 Then
MessageBox.Show("Just to demonstrate data input validation, this example rejects empty cells. Please enter some data.")
e.inputValid = False
End If
End Sub
Private Sub AxSftTree1_EditEnding(ByVal sender As Object, ByVal e As AxSftTreeLib75._DSftTreeEvents_EditEndingEvent) Handles AxSftTree1.EditEnding
' Save the new cell contents
If e.saveInput Then
If e.vData Is Text1 Then
AxSftTree1.get_Cell(e.editIndex, e.editCol).Text = Text1.Text
Else
AxSftTree1.get_Cell(e.editIndex, e.editCol).Text = Combo1.Text
End If
End If
Dim ctrl As Control
ctrl = e.vData
ctrl.Visible = False
ctrl.Enabled = False
End Sub
Private Sub AxSftTree1_CaretChange(ByVal sender As System.Object, ByVal e As AxSftTreeLib75._DSftTreeEvents_CaretChangeEvent) Handles AxSftTree1.CaretChange
End Sub
End Class