Hide

SftTree/OCX 7.5 - ActiveX Tree Control

Display
Print

Virtual Sample (C#)

This sample illustrates using virtual mode with cell editing.

The source code is located at C:\Program Files (x86)\Softelvdm\SftTree OCX 7.5\Samples\Visual Studio - CSharp\Virtual\Form1.cs or C:\Program Files\Softelvdm\SftTree OCX 7.5\Samples\Visual Studio - CSharp\Virtual\Form1.cs (on 32-bit Windows versions).


        public int m_PicCount;  // spinning globe index

        private void Command1_Click(object sender, System.EventArgs e) {
            Application.Exit();
        }

        private void Form1_Load(object sender, System.EventArgs e) {
            m_PicCount = 0;
            axSftTree1.VirtualMode = true;
            axSftTree1.VirtualCount(10000000);
            axSftTree1.VirtualImageSizes(16, 16, 16, 16, 16, 16, 16, 16);
            // Make columns and row headers optimal
            // but do this at the end of the list, because our sample
            // data is larger at the end
            axSftTree1.Items.TopIndex = axSftTree1.Items.Count - 1;
            axSftTree1.ColumnsObj.MakeOptimal();
            axSftTree1.RowHeaders.MakeOptimal();
            axSftTree1.Items.RecalcHorizontalExtent();
            axSftTree1.Items.TopIndex = 0;
       }

        private void Timer1_Tick(object sender, System.EventArgs e) {
            axSftTree1.RowColumnHeader.Image.NETImageObject = imageListWorld.Images[m_PicCount];
            ++m_PicCount;
            if (m_PicCount >= imageListWorld.Images.Count)
                m_PicCount = 0;
        }

        private void axSftTree1_VirtualItem(object sender, AxSftTreeLib75._DSftTreeEvents_VirtualItemEvent e) {

            e.itemObject.Item.get_Cell(0).Text = "Item " + e.rowIndex;
            e.itemObject.Item.get_Cell(1).Text = "Cell " + e.rowIndex.ToString();
            e.itemObject.Item.get_Cell(2).Text = "A";
            e.itemObject.Item.get_Cell(3).Text = (e.rowIndex % 7).ToString();
            e.itemObject.Item.get_Cell(4).Text = "Last " + e.rowIndex.ToString();
            e.itemObject.Item.RowHeader.Text = "R" + e.rowIndex.ToString();
            e.itemObject.Item.Enabled = ((e.rowIndex % 2) == 0);

            if (e.rowIndex % 17 == 0)
                e.itemObject.Item.RowHeader.Image.NETImageObject = imageListBitmaps.Images[e.rowIndex % 10];
            if (e.rowIndex % 3 == 0) {
                e.itemObject.Item.get_Cell(1).ForeColor = OLECvt.ToOleColor(System.Drawing.Color.Red);
                e.itemObject.Item.get_Cell(1).BackColor = OLECvt.ToOleColor(System.Drawing.Color.Aqua);
            }
            if (e.rowIndex % 5 == 0)
                e.itemObject.Item.get_Cell(1).Font.Bold = true;
            if (e.rowIndex % 7 == 0) {
                e.itemObject.Item.Image.NETImageObject = imageListBitmaps.Images[(e.rowIndex + 9) % 10];
                e.itemObject.Item.LabelImage.NETImageObject = imageListBitmaps.Images[(e.rowIndex + 1) % 10];
            }
            if (e.rowIndex % 13 == 0)
                e.itemObject.Item.RowHeader.Image.NETImageObject = imageListBitmaps.Images[(e.rowIndex + 5) % 10];
            if (e.rowIndex % 11 == 0)
                e.itemObject.Item.RowHeader.ImageHAlign = SftTreeHAlignConstants.halignSftTreeRight;
            if (e.rowIndex % 9 == 0)
                e.itemObject.Item.get_Cell(1).Image.NETImageObject = imageListBitmaps.Images[(e.rowIndex + 3) % 10];
            if (e.rowIndex % 7 == 0) {
                e.itemObject.Item.get_Cell(0).Image.NETImageObject = imageListBitmaps.Images[(e.rowIndex + 2) % 10];
                e.itemObject.Item.get_Cell(0).ImageHAlign = SftTreeHAlignConstants.halignSftTreeRight;
            }
        }

        private void axSftTree1_ItemClick(object sender, AxSftTreeLib75._DSftTreeEvents_ItemClickEvent e) {
            if ((SftTreeAreaTypeConstants) e.areaType == SftTreeAreaTypeConstants.constSftTreeText)
                axSftTree1.get_Cell(e.itemIndex, e.colIndex).Edit(0, 0);
        }

        private void axSftTree1_ItemDblClick(object sender, AxSftTreeLib75._DSftTreeEvents_ItemDblClickEvent e) {
            if ((SftTreeAreaTypeConstants) e.areaType == SftTreeAreaTypeConstants.constSftTreeColumnRes)
                axSftTree1.get_Column(e.colIndex).MakeOptimal();

        }

        private void axSftTree1_EditInitializing(object sender, AxSftTreeLib75._DSftTreeEvents_EditInitializingEvent e) {

            Timer1.Enabled = false; // stop the spinning globe

            // 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 - EditControl.Height) / 2;
            e.heightPix = EditControl.Height;

            // Set the text in the control used for cell editing and
            // set other control-specific properties
            EditControl.Width = 200;
            EditControl.Text = axSftTree1.get_Cell(e.editIndex, e.editCol).Text;
            EditControl.SelectionStart = 0;
            EditControl.SelectionLength = 999;

            // Return the control's window handle
            e.window = (int) EditControl.Handle;
            e.vData = EditControl;

            // Define navigation keys
            // VK_TAB
            axSftTree1.CellEditIntercept(9, SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeChar | SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeControlChar | SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeShiftChar);
            // VK_RETURN
            axSftTree1.CellEditIntercept(13, SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeChar | SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeControlChar | SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeShiftChar);
            // VK_HOME
            axSftTree1.CellEditIntercept(36, SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeControlChar);
            // VK_END
            axSftTree1.CellEditIntercept(35, SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeControlChar);
            // VK_UP
            axSftTree1.CellEditIntercept(38, SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeChar | SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeControlChar | SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeShiftChar);
            // VK_DOWN
            axSftTree1.CellEditIntercept(40, SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeChar | SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeControlChar | SftTreeCellEditInterceptStyleConstants.cellEditInterceptSftTreeShiftChar);
        }

        private void axSftTree1_EditNavigating(object sender, AxSftTreeLib75._DSftTreeEvents_EditNavigatingEvent e) {
            // Process key pressed
            axSftTree1.EditNavigate(e.key, e.shift);
        }

        private void axSftTree1_EditValidate(object sender, AxSftTreeLib75._DSftTreeEvents_EditValidateEvent e) {
            // Validate the new cell contents
            if (EditControl.Text != axSftTree1.get_Cell(e.editIndex, e.editCol).Text)
                MessageBox.Show("This example doesn't preserve the changes you make, because the sample data is randomly generated.");
        }

        private void axSftTree1_EditEnding(object sender, AxSftTreeLib75._DSftTreeEvents_EditEndingEvent e) {
            Control ctrl = (Control) e.vData;
            ctrl.Visible = false;
            ctrl.Enabled = false;
        }

        private void axSftTree1_EditEnded(object sender, AxSftTreeLib75._DSftTreeEvents_EditEndedEvent e) {
            Timer1.Enabled = true; // restart the spinning globe
        }

    }
}

Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.