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 ToolTip1 As System.Windows.Forms.ToolTip Public WithEvents Combo1 As System.Windows.Forms.ComboBox Public WithEvents Text1 As System.Windows.Forms.TextBox Public WithEvents Command1 As System.Windows.Forms.Button Public WithEvents Label5 As System.Windows.Forms.Label Public WithEvents Label1 As System.Windows.Forms.Label 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.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components) Me.Combo1 = New System.Windows.Forms.ComboBox Me.Text1 = New System.Windows.Forms.TextBox Me.Command1 = New System.Windows.Forms.Button Me.Label5 = New System.Windows.Forms.Label Me.Label1 = New System.Windows.Forms.Label Me.SftHelperComponent1 = New Softelvdm.OCXHelper.SftHelperComponent(Me.components) CType(Me.AxSftTree1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'AxSftTree1 ' Me.AxSftTree1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.AxSftTree1.Location = New System.Drawing.Point(8, 24) 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, 553) Me.AxSftTree1.TabIndex = 21 ' 'Combo1 ' Me.Combo1.BackColor = System.Drawing.SystemColors.Window Me.Combo1.Cursor = System.Windows.Forms.Cursors.Default Me.Combo1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Combo1.ForeColor = System.Drawing.SystemColors.WindowText Me.Combo1.Location = New System.Drawing.Point(502, 144) Me.Combo1.Name = "Combo1" Me.Combo1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Combo1.Size = New System.Drawing.Size(81, 21) Me.Combo1.TabIndex = 19 Me.Combo1.Text = "Combo1" Me.Combo1.Visible = False ' 'Text1 ' Me.Text1.AcceptsReturn = True Me.Text1.AutoSize = False Me.Text1.BackColor = System.Drawing.SystemColors.Window Me.Text1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.Text1.Cursor = System.Windows.Forms.Cursors.IBeam Me.Text1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Text1.ForeColor = System.Drawing.SystemColors.WindowText Me.Text1.Location = New System.Drawing.Point(502, 112) Me.Text1.MaxLength = 0 Me.Text1.Name = "Text1" Me.Text1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Text1.Size = New System.Drawing.Size(81, 20) Me.Text1.TabIndex = 18 Me.Text1.Text = "Text1" Me.Text1.Visible = False ' 'Command1 ' Me.Command1.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) 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.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Command1.ForeColor = System.Drawing.SystemColors.ControlText Me.Command1.Location = New System.Drawing.Point(502, 8) Me.Command1.Name = "Command1" Me.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Command1.Size = New System.Drawing.Size(81, 25) Me.Command1.TabIndex = 15 Me.Command1.Text = "Close" ' 'Label5 ' Me.Label5.BackColor = System.Drawing.SystemColors.Control Me.Label5.Cursor = System.Windows.Forms.Cursors.Default Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label5.ForeColor = System.Drawing.SystemColors.ControlText Me.Label5.Location = New System.Drawing.Point(502, 192) Me.Label5.Name = "Label5" Me.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label5.Size = New System.Drawing.Size(81, 201) Me.Label5.TabIndex = 20 Me.Label5.Text = "Click on the SftTree/OCX control and hit F1 to access online help for SftTree/OCX" & _ " 6.0" Me.Label5.Visible = False ' '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.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText Me.Label1.Location = New System.Drawing.Point(6, 8) Me.Label1.Name = "Label1" Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label1.Size = New System.Drawing.Size(489, 16) Me.Label1.TabIndex = 16 Me.Label1.Text = "Simple Cell Editing Sample with edit controls and combo boxes." ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.CancelButton = Me.Command1 Me.ClientSize = New System.Drawing.Size(589, 590) Me.Controls.Add(Me.Combo1) Me.Controls.Add(Me.Text1) Me.Controls.Add(Me.Command1) Me.Controls.Add(Me.Label5) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.AxSftTree1) Me.Name = "Form1" Me.Text = "Softel vdm, Inc. - CellEditing Sample" CType(Me.AxSftTree1, 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 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 AxSftTreeLib70._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 AxSftTreeLib70._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 AxSftTreeLib70._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 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 = 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 AxSftTreeLib70._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 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 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 AxSftTreeLib70._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 AxSftTreeLib70._DSftTreeEvents_CaretChangeEvent) Handles AxSftTree1.CaretChange End Sub End Class