Imports AxSftTreeLib70
Imports SftTreeLib70
Imports Softelvdm.OLEConvert
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Public WithEvents Label1 As System.Windows.Forms.Label
Public WithEvents ToolTip1 As System.Windows.Forms.ToolTip
Friend WithEvents SftBox1 As AxSftBoxLib40.AxSftBox
Friend WithEvents SftMaskDateTime As AxSftMaskLib60.AxSftMask
Friend WithEvents SftMaskAmount As AxSftMaskLib60.AxSftMask
Public WithEvents Command1 As System.Windows.Forms.Button
Public WithEvents Text1 As System.Windows.Forms.TextBox
Friend WithEvents AxSftTree1 As AxSftTreeLib70.AxSftTree
Friend WithEvents SftHelperComponent1 As Softelvdm.OCXHelper.SftHelperComponent
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.AxSftTree1 = New AxSftTreeLib70.AxSftTree()
Me.Label1 = New System.Windows.Forms.Label()
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.SftBox1 = New AxSftBoxLib40.AxSftBox()
Me.SftMaskDateTime = New AxSftMaskLib60.AxSftMask()
Me.SftMaskAmount = New AxSftMaskLib60.AxSftMask()
Me.Command1 = New System.Windows.Forms.Button()
Me.Text1 = New System.Windows.Forms.TextBox()
Me.SftHelperComponent1 = New Softelvdm.OCXHelper.SftHelperComponent(Me.components)
CType(Me.AxSftTree1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.SftBox1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.SftMaskDateTime, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.SftMaskAmount, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'AxSftTree1
'
Me.AxSftTree1.Location = New System.Drawing.Point(7, 39)
Me.AxSftTree1.Name = "AxSftTree1"
Me.AxSftTree1.OcxState = CType(resources.GetObject("AxSftTree1.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxSftTree1.Size = New System.Drawing.Size(489, 264)
Me.AxSftTree1.TabIndex = 25
'
'Label1
'
Me.Label1.BackColor = System.Drawing.SystemColors.Control
Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.0!)
Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label1.Location = New System.Drawing.Point(7, 7)
Me.Label1.Name = "Label1"
Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label1.Size = New System.Drawing.Size(489, 25)
Me.Label1.TabIndex = 21
Me.Label1.Text = "Cell Editing with separately available ActiveX controls."
'
'SftBox1
'
Me.SftBox1.Location = New System.Drawing.Point(391, 367)
Me.SftBox1.Name = "SftBox1"
Me.SftBox1.OcxState = CType(resources.GetObject("SftBox1.OcxState"), System.Windows.Forms.AxHost.State)
Me.SftBox1.Size = New System.Drawing.Size(192, 19)
Me.SftBox1.TabIndex = 26
Me.SftBox1.Visible = False
'
'SftMaskDateTime
'
Me.SftMaskDateTime.DataSource = Nothing
Me.SftMaskDateTime.Location = New System.Drawing.Point(407, 399)
Me.SftMaskDateTime.Name = "SftMaskDateTime"
Me.SftMaskDateTime.OcxState = CType(resources.GetObject("SftMaskDateTime.OcxState"), System.Windows.Forms.AxHost.State)
Me.SftMaskDateTime.Size = New System.Drawing.Size(177, 19)
Me.SftMaskDateTime.TabIndex = 24
Me.SftMaskDateTime.Visible = False
'
'SftMaskAmount
'
Me.SftMaskAmount.DataSource = Nothing
Me.SftMaskAmount.Location = New System.Drawing.Point(407, 335)
Me.SftMaskAmount.Name = "SftMaskAmount"
Me.SftMaskAmount.OcxState = CType(resources.GetObject("SftMaskAmount.OcxState"), System.Windows.Forms.AxHost.State)
Me.SftMaskAmount.Size = New System.Drawing.Size(177, 19)
Me.SftMaskAmount.TabIndex = 23
Me.SftMaskAmount.Visible = False
'
'Command1
'
Me.Command1.BackColor = System.Drawing.SystemColors.Control
Me.Command1.Cursor = System.Windows.Forms.Cursors.Default
Me.Command1.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Command1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.0!)
Me.Command1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Command1.Location = New System.Drawing.Point(503, 7)
Me.Command1.Name = "Command1"
Me.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Command1.Size = New System.Drawing.Size(81, 25)
Me.Command1.TabIndex = 20
Me.Command1.Text = "Close"
'
'Text1
'
Me.Text1.AcceptsReturn = True
Me.Text1.AutoSize = False
Me.Text1.BackColor = System.Drawing.SystemColors.Control
Me.Text1.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.Text1.Cursor = System.Windows.Forms.Cursors.IBeam
Me.Text1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Text1.ForeColor = System.Drawing.SystemColors.WindowText
Me.Text1.Location = New System.Drawing.Point(8, 312)
Me.Text1.MaxLength = 0
Me.Text1.Multiline = True
Me.Text1.Name = "Text1"
Me.Text1.ReadOnly = True
Me.Text1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Text1.Size = New System.Drawing.Size(488, 177)
Me.Text1.TabIndex = 28
Me.Text1.TabStop = False
Me.Text1.Text = "" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "This sample can only be opened and modified if SftMask/OCX 6.0 and SftBox/OCX 4" & _
".0 (demo or product) are also installed." & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "Click on the SftTree/OCX control a" & _
"nd hit F1 to access online help for SftTree/OCX 7.0."
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.CancelButton = Me.Command1
Me.ClientSize = New System.Drawing.Size(590, 495)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Text1, Me.AxSftTree1, Me.Label1, Me.SftBox1, Me.SftMaskDateTime, Me.SftMaskAmount, Me.Command1})
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Name = "Form1"
Me.Text = "Softel vdm, Inc. - CellEditingII Sample"
CType(Me.AxSftTree1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.SftBox1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.SftMaskDateTime, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.SftMaskAmount, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
'--locate-marker--
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 AxSftTreeLib70._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 AxSftTreeLib70._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 AxSftTreeLib70._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 AxSftTreeLib70._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 AxSftTreeLib70._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 AxSftTreeLib70._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 AxSftTreeLib70._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 AxSftTreeLib70._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 AxSftMaskLib60._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