Once the data is loaded into the array, the array's contents can be transferred to the FlexGrid using the Format function or Round function in VB6 to truncate values. Likewise edited values should be retrieved from the array to the txtDataEntry TextBox in the example above, and returned to the array upon completion of editing. A function should be called to dump the array to the FlexGrid upon data retrieval or amendment.
Saving the FlexGrids data should then be a data dump from the array to the database or other data source. This code sums to values in the first 5 rows of the first column in the FlexGrid and places the total in the row 7, column 1 in a monetary format. Using the code examples above for the FlexGrid events we can use addition code to restrict data entry to specific cells or regions of the FlexGrid.
Here data entry is only permitted in row 6 and between columns 4 and 8. These can be trapped in the TextBox KeyDown event see below which fires before the TextBox KeyPress event coded above, and processed to carried out their required action. The following code example takes a recordset which contains two fields one which hold share prices, shareprice , and one for share movements, movement , and colour codes grid cells depending on the status of the data: With rsExample.
MoveFirst Do If! MoveNext Loop Until. CellHeight txtDataEntry. Text txtDataEntry. Remember to include a call to the procedure to transfer the array data to the FlexGrid. Trapping Restricted Cell Rows and Columns Using the code examples above for the FlexGrid events we can use addition code to restrict data entry to specific cells or regions of the FlexGrid. SetFocus Case 13 'Return grdGrid. FixedCols Then grdGrid. FixedRows Then grdGrid.
Cols - 1 Then grdGrid. The primary keys are Claim No. The only person with the capability to open the record set is the one with the same UserID. It is a program to write estimates with and after the user is finished, all of the data entered in the FlexGrid is inserted into the database.
If a suppliment to the estimate is needed, all of the prior information is loaded back into the flexgrid and the supplimental items then added. I'll give what you said a try I think it should work. Red Flag This Post Please let us know here why this post is inappropriate.
Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework. The Tek-Tips staff will check this out and take appropriate action. Click Here to join Tek-Tips and talk with other members! Already a Member? Join your peers on the Internet's largest technical computer professional community. It's easy to join and it's free.
Register now while it's still free! Already a member? The second method uses a hidden column and lets the grid do the work. Suppose you have a database field that returns a date in the Short Date format. Neither a numeric sort nor a string sort would order this column correctly. To sort by date you need to add an extra column to the grid and set its width to zero.
The advantage of this approach is that you can tailor editing behavior to your taste. The basic technique involves smoke and mirrors: the editing occurs not in MSFlexGrid at all, but in a standard Textbox control that is positioned precisely over the cell being edited.
In this example, we will give the user two ways to get into the edit mode, either by double-clicking on a cell, or by simply starting to type in the current cell. In the case of double-clicking, we pass the space character as a flag. FontName Text1. Left Text1. Top Text1. CellWidth Text1. CellHeight Text1. SetFocus End Sub For demonstration purposes, the Case statement in the GridEdit routine shows two different behaviors when entering the edit mode.
In practice you would probably only use one of them, or a different one of your own creation. If the edit mode is entered by virtue of a double-click or a control key press, we copy the contents of the grid cell to the exit box and place the cursor at the end of the string.
If the edit mode is entered by pressing a normal key, we ignore the original cell contents and insert the pressed key into the edit box. The positioning of the exit box could be done on one line with the Move method.
Here we have used four lines so that it reads more easily in this article. Notice that MSFlexGrid conveniently gives us all the coordinate information we need. Next, we need a couple of routines that handle housekeeping when the user moves to a different cell or moves focus back to the grid from another control.
The LeaveCell event is also the place where you would put any data validation code that might be applicable. To really fine-tune this code, the edit box needs a slight additional offset to the southeast with a corresponding reduction in size so that the text in it lines up exactly with the text in the cell beneath. You would probably also want to write some code behind the scroll event of the grid since clicking on the grid's scroll bar will not cause the edit box to loose focus.
Note that this technique is not limited to using a Textbox as your edit box. You could modify the sample code to use a ComboBox, a CheckBox, or even a calendar control for editing, based on the column being edited. MSFlexGrid is a very flexible control indeed, and this article just touches on some of the things you can do with it. As you gain familiarity with it, it will become a more regular part of your toolbox.
Cell merging and pivoting are two more unique features of the MSFlexGrid that give it tremendous power and bear investigation. Send feedback on this article. Find support options. All rights reserved. Terms of use.
0コメント