Edit input with Microsoft grid controls
(Author: Limei, 2001 at 16:51 on January 18)
Many standard controls and custom controls are available in Visual Basic, each of which provides a special user interface and programming capabilities. Take advantage of the features and methods of each control can make programming work easier and simple. Microsoft Grid Controls MSFlexGRID is a custom control. Using Microsoft Grid Controls, you can display the body, numbers, and pictures in the order of order, just like a spreadsheet. Both the height, width, and other features of the grid can be adjusted, and the rows and columns of the grid can be operated in a single place or in groups. The MSFlexGrid control can be classified, merge, and format the unit content included in the included, and can be bonded to the database control. The MSFlexGrid control has more than 50 properties, more powerful than other grid controls, and more flexible. However, the MSFlexGrid control is the same as other GRID grid controls, and the user cannot edit the content in the grid unit, which may be a defect when modifying its content. Although the DBGRID control can be programmed to perform editing, it is not as strong as MSFLEXGRID. When the entry work is relatively large, if you enter the MSFLExGrid, instead of Text or other controls, it avoids the repeated refresh and constant operation buttons of the interface, and the entry speed and efficiency will be greatly improved. Before using MSFLEXGRID in your application, you should add the MSFLXGRD.OCX file to the project. Implementation of editing mesh units In order to simply implement entries that can be input to the grid unit, the following code can be added to the keypress event of MSFLExGrid, but the content after modifying the editing is also very difficult. Sub msflexgrid1_keypress (keyascii as integer) MSFLEXGRID1.TEXT = MSFLEXGRID1.TEXT & CHR $ (Keyascii) End subs is another method is the combination of text boxes and grids, the user edits the contents of the operation text box, moved to the network after operation In the grid unit. In this process, the following features should be implemented: (1) The text box can be accurately positioned, and the text box is not displayed with the mesh unit (2) timing text box, when the editing operation is displayed (3) is input After one line, you can automatically judge and add a new line (4) Press the Enter key to confirm and automatically go to the next column (5) Double-click the grid unit to display the text box for editing (6) After the text box disappears, move the text box content to In the grid unit. Editing the specific implementation of the grid unit creates a new project, add control Text1 and MSFlexGRID1 on Form1, set its properties according to Table 1.
Table 1 Objects and properties of forms Form1
Object Property Setting Text1Visiblefalsetext "" MSFLEXGRID1ROWS2COLS The number of FixedCols0FixedRows1 according to the number of fields First, when you want to implement the text box, you can accurately coincide with the grid unit. This feature can be implemented in the ShowTextbox subroutine. Consider the TOP and LEFT values of the grid itself, the height and width of the mesh unit, the width of the border of the grid unit. Sub showtextbox () with msflexgrid1 'hides text box, set height and width text1.visible = false text1.height = .rowHeight (.row) - (Screen.twipsperpixly) * 2 text1.width = .COLWIDTH (.col)' calculation Text box left coordinate text1.left = .cellleft .left text1.top = .celltop .top text1.visible = true text1.setfocus End with end Sub When the button is triggered, the content in the unit is saved. Go to the text box, then display the text box waiting for editing. Private Sub MSFlexGrid1_KeyPress (KeyAscii As Integer) Dim char As String If KeyAscii = 13 Then Text1.Text = MSFlexGrid1.Text Text1.SelStart = Len (Text1.Text) Else char = Chr $ (KeyAscii) Text1.Text = char Text1.SelStart = 1 End If ShowTextBox Keyascii = 0 End Sub When the focus leaves a grid unit, first save the contents in the text box to the grid unit, and then detect whether the departure unit is in the largest line (you can set up a few) If it is automatically added. Private Sub MSFlexGrid1_LeaveCell () MSFlexGrid1.Text = Text1.Text If MSFlexGrid1.Col = 0 And MSFlexGrid1.Row <> 0 And _ MSFlexGrid1.Row = MSFlexGrid1.Rows - 1 And MSFlexGrid1.Text <> "" Then MSFlexGrid1.Rows = MSFlexGrid1 .ROWS 1 End if End Sub Add the following code in order to respond to the mouse action. Private Sub MSFLEXGRID1_MOUSEDOWN (Button As Integer, Shift As Integer, _ x as single, y as single) text1.visible = false End Sub When the grid unit changes, the grid unit content to the text box, waiting to be edited, thus ensuring The content in the text box is the latest. Private sub msflexgrid1_rowcolchange () text1.text = msflexGRID1.TEXT END SUB Double-click the grid unit to edit the content in the grid unit.