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\CellEditingII\Form1.vb or C:\Program Files\Softelvdm\SftTree OCX 7.5\Samples\Visual Studio - VB.NET\CellEditingII\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 Dim s As String Text1.Text = "In this example, the first column uses a SftMask/OCX Masked Edit control to enter an amount. Try entering a new amount, then type + or - to access the built-in popup calculator." & ControlChars.CrLf & ControlChars.CrLf & "The second column uses a SftBox/OCX Combo Box control." & ControlChars.CrLf & ControlChars.CrLf & "The last column again uses a SftMask/OCX Masked Edit control to enter a date. Click on the drop down button to access the popup calendar." ItemIndex = AxSftTree1.Items.Add("Edit cells" & ControlChars.CrLf & "using SftMask/OCX:") AxSftTree1.get_Item(ItemIndex).EditIgnore = True AxSftTree1.get_Cell(ItemIndex, 1).Text = ControlChars.CrLf & "using SftBox/OCX:" AxSftTree1.get_Cell(ItemIndex, 2).Text = "and again" & ControlChars.CrLf & "using SftMask/OCX:" Dim Dt As DateTime ItemIndex = AxSftTree1.Items.Add("5.33") AxSftTree1.get_Cell(ItemIndex, 0).TextHAlign = SftTreeHAlignDefaultConstants.halignSftTreeDefaultRight AxSftTree1.get_Cell(ItemIndex, 1).Text = "Option 1" Dt = DateTime.Today.AddDays(-1) s = "short" SftMaskDateTime.Calendar.FormatDate(Dt, s) AxSftTree1.get_Cell(ItemIndex, 2).Text = s AxSftTree1.get_Cell(ItemIndex, 2).DataTag = Dt ItemIndex = AxSftTree1.Items.Add("122.33") AxSftTree1.get_Cell(ItemIndex, 0).TextHAlign = SftTreeHAlignDefaultConstants.halignSftTreeDefaultRight AxSftTree1.get_Cell(ItemIndex, 1).Text = "Option 3" Dt = DateTime.Today s = "short" SftMaskDateTime.Calendar.FormatDate(Dt, s) AxSftTree1.get_Cell(ItemIndex, 2).Text = s AxSftTree1.get_Cell(ItemIndex, 2).DataTag = Dt ItemIndex = AxSftTree1.Items.Add("66.05") AxSftTree1.get_Cell(ItemIndex, 0).TextHAlign = SftTreeHAlignDefaultConstants.halignSftTreeDefaultRight AxSftTree1.get_Cell(ItemIndex, 1).Text = "Option 2" Dt = DateTime.Today.AddDays(1) s = "short" SftMaskDateTime.Calendar.FormatDate(Dt, s) AxSftTree1.get_Cell(ItemIndex, 2).Text = s AxSftTree1.get_Cell(ItemIndex, 2).DataTag = Dt AxSftTree1.ColumnsObj.MakeOptimal() AxSftTree1.RowHeaders.MakeOptimal() AxSftTree1.Items.RecalcHorizontalExtent() AxSftTree1.get_Item(0).Selected = True End Sub Private Sub AxSftTree1_ItemClick(ByVal sender As Object, ByVal e As AxSftTreeLib75._DSftTreeEvents_ItemClickEvent) Handles AxSftTree1.ItemClick ' User clicked on a cell Dim AreaType As SftTreeAreaTypeConstants AreaType = e.areaType If AreaType = SftTreeAreaTypeConstants.constSftTreeCellText Then AxSftTree1.get_Cell(e.itemIndex, e.colIndex).Edit(0, 0) End If 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 = 0 Then ctrl = SftMaskAmount ElseIf e.editCol = 1 Then ctrl = SftBox1 Else ctrl = SftMaskDateTime 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 SftMaskAmount Then SftMaskAmount.Text = AxSftTree1.get_Cell(e.editIndex, e.editCol).Text SftMaskAmount.SelStart = 0 SftMaskAmount.SelLength = 999 ElseIf ctrl Is SftMaskDateTime Then Dim Dt As DateTime Dt = AxSftTree1.get_Cell(e.editIndex, e.editCol).DataTag SftMaskDateTime.Contents.DateTime = Dt Else SftBox1.Items.Clear() Dim ItemIndex As Integer ItemIndex = SftBox1.Items.Add("Option 1") SftBox1.get_Cell(ItemIndex, 1).Text = "Description for option 1" ItemIndex = SftBox1.Items.Add("Option 2") SftBox1.get_Cell(ItemIndex, 1).Text = "Description for option 2" ItemIndex = SftBox1.Items.Add("Option 3") SftBox1.get_Cell(ItemIndex, 1).Text = "Description for option 3" Dim S As String S = AxSftTree1.get_Cell(e.editIndex, e.editCol).Text If SftBox1.Items.Find(S, 0, 0, False, True, True) < 0 Then ItemIndex = SftBox1.Items.Add(S) SftBox1.get_Cell(ItemIndex, 1).Text = "Description for " + S End If SftBox1.Columns.MakeOptimal(0) SftBox1.RecalcHorizontalExtent(0) SftBox1.Edit.Text = S 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 SftMaskAmount Then ' We want these keys just for the amount 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 ' We position the control (ActiveX controls must be positioned using the EditInitialized event) e.positioned = True Dim ctrl As Control ctrl = e.vData If ctrl Is SftMaskAmount Then SftMaskAmount.Left = e.leftPix SftMaskAmount.Top = e.topPix SftMaskAmount.Width = e.widthPix SftMaskAmount.Height = e.heightPix SftMaskAmount.Enabled = True SftMaskAmount.Visible = True SftMaskAmount.Focus() ElseIf ctrl Is SftMaskDateTime Then SftMaskDateTime.Left = e.leftPix SftMaskDateTime.Top = e.topPix SftMaskDateTime.Width = e.widthPix SftMaskDateTime.Height = e.heightPix SftMaskDateTime.Enabled = True SftMaskDateTime.Visible = True SftMaskDateTime.Focus() Else SftBox1.Left = e.leftPix SftBox1.Top = e.topPix SftBox1.Width = e.widthPix SftBox1.Height = e.heightPix SftBox1.Enabled = True SftBox1.Visible = True SftBox1.Focus() SftBox1.Edit.SetSelection(0, -1) SftBox1.DropDown.Dropped = 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 Dim ctrl As Control ctrl = e.vData If ctrl Is SftMaskAmount Then If Not SftMaskAmount.Contents.Valid() Then ' could validate End If S = SftMaskAmount.TextDisplay ElseIf ctrl Is SftMaskDateTime Then If Not SftMaskDateTime.Contents.Valid() Then MessageBox.Show("Please enter a valid date.") e.inputValid = False Exit Sub End If S = SftMaskDateTime.TextDisplay Else S = SftBox1.Edit.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 Dim ctrl As Control ctrl = e.vData If ctrl Is SftMaskAmount Then SftMaskAmount.Visible = False SftMaskAmount.Enabled = False If e.saveInput Then AxSftTree1.get_Cell(e.editIndex, e.editCol).Text = SftMaskAmount.TextDisplay End If ElseIf ctrl Is SftMaskDateTime Then SftMaskDateTime.Visible = False SftMaskDateTime.Enabled = False If e.saveInput Then AxSftTree1.get_Cell(e.editIndex, e.editCol).Text = SftMaskDateTime.TextDisplay AxSftTree1.get_Cell(e.editIndex, e.editCol).DataTag = SftMaskDateTime.Contents.DateTime End If Else SftBox1.Visible = False SftBox1.Enabled = False If e.saveInput Then AxSftTree1.get_Cell(e.editIndex, e.editCol).Text = SftBox1.Edit.Text 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 SftMaskAmount_UpDownPress(ByVal sender As Object, ByVal e As AxSftMaskLib70._ISftMaskEvents_UpDownPressEvent) Handles SftMaskAmount.UpDownPress Dim Amount As Double Dim Increment As Double If e.counter = 0 Or e.counter > 5 Then Amount = Convert.ToDouble(e.field) Increment = 0.01 If e.counter > 14 Then Increment = 0.1 If e.counter > 23 Then Increment = 1 If e.counter > 52 Then Increment = 10 If e.up Then Amount = Amount + Increment Else Amount = Amount - Increment End If If Amount > 99999.99 Then Amount = 99999.99 If Amount < -99999.99 Then Amount = -99999.99 e.field = Amount.ToString("N2") End If End Sub End Class