399 403




Visual Basic 6 Black Book:The Chart And Grid Controls
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Black Book (Publisher: The Coriolis Group) Author(s): Steven Holzner ISBN: 1576102831 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




When the user clicks another cell, a LeaveCell event is generated, and we can take advantage of that event to transfer the text from the text box to the current cell and hide the text box. Note that if the text box is not visible—in other words, the user is just moving around in the flex grid—we do not want to transfer the text from the text box to the current cell, and so we exit the procedure in that case:


Sub MSFlexGrid1_LeaveCell()
If Text1.Visible = False Then
Exit Sub
End If
...


Otherwise, we transfer the text from the text box to the current cell, clear the text box, and hide it:



Sub MSFlexGrid1_LeaveCell()
If Text1.Visible = False Then
Exit Sub
End If
MSFlexGrid1.Text = Text1
Text1.Visible = False
Text1.Text = ""
End Sub


And that’s it. Now users can use the text box to enter text in a way that makes it look as though they’re entering text directly into the flex grid, as shown in Figure 12.16. The code for this example is located in the flex folder on this book’s accompanying CD-ROM.


Figure 12.16  Using a text box for flex grid data entry.
Setting Flex Grid Grid Lines And Border Styles
You can set what types of grid lines a flex grid uses with the GridLines property. These can be set at design time or runtime to the following values:

•  flexGridNone
•  flexGridFlat
•  flexGridInset
•  flexGridRaised

You can set the grid line width with the GridLineWidth property.
In addition, you can set the BorderStyle property to show a border around the whole control, or no border at all:

•  flexBorderNone
•  flexBorderSingle

Labeling Rows And Columns In A Flex Grid
The usual convention in spreadsheets is to label the top row with letters and the first column with numbers. Here’s some code to do just that (note that we use the Visual Basic Chr and Asc functions to set up the letters and enter text directly into the flex grid using its TextArray property, which holds the grid’s text in array form):


Sub Form_Load()
Dim intLoopIndex As Integer

For intLoopIndex = MSFlexGrid1.FixedRows To MSFlexGrid1.Rows – 1
MSFlexGrid1.TextArray(MSFlexGrid1.Cols * intLoopIndex) =_
intLoopIndex
Next

For intLoopIndex = MSFlexGrid1.FixedCols To MSFlexGrid1.Cols – 1
MSFlexGrid1.TextArray(intLoopIndex) = Chr(Asc("A") +_
intLoopIndex – 1)
Next
End Sub



TIP:  The columns and rows you label in a flex grid are usually colored gray; you set the number of label columns and rows with the FixedCols and FixedRows properties.

Formatting Flex Grid Cells
The Aesthetic Design Department is calling again. Can’t you use italics in that spreadsheet? Hmm, you think—can you?
Yes, you can: flex grid cells support formatting, including word wrap. You can format text using these properties of flex grids:

•  CellFontBold
•  CellFontItalic
•  CellFontName
•  CellFontUnderline
•  CellFontStrikethrough
•  CellFontSize

Besides the preceding properties, you can size cells as you like using the CellWidth and RowHeight properties.
Sorting A Flex Grid Control
The Testing Department is calling again. Your new program, SuperDuperDataCrunch, is terrific, but why can’t the user sort the data in your spreadsheet? Sounds like a lot of work, you think.
Actually, it’s easy. You just use the flex grid’s Sort property (available only at runtime). For example, to sort a flex grid according to the values in column 1 when the user clicks a button, add this code to your program (setting Sort to 1 sorts the flex grid on ascending values):


Private Sub Command1_Click()
MSFlexGrid1.Col = 1
MSFlexGrid1.Sort = 1
End Sub



TIP:  Note that when the user clicks a column, that column becomes the new default column in the Col property, so if you want to let the user click a column and sort based on the values in that column, omit the MSFlexGrid1.Col = 1 in the preceding code.

Dragging Columns In A Flex Grid Control
One of the attractive aspects of flex grids is that you can use drag-and-drop with them to let users rearrange the flex grid as they like. To see how this works, we’ll write an example here that lets users drag and move columns around in a flex grid.

When the user presses the mouse button to start the drag operation, we store the column where the mouse went down in a form-wide variable named, say, intDragColumn in the MouseDown event. This event is stored in the flex grid’s MouseCol property:


Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)

intDragColumn = MSFlexGrid1.MouseCol
...


We also add that variable, intDragColumn, to the (General) declaration area of the form:


Dim intDragColumn As Integer


Then we start the drag and drop operation for the column in the flex grid:



Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)

intDragColumn = MSFlexGrid1.MouseCol
MSFlexGrid1.Drag 1

End Sub


Finally, when the user drags the column to a new location and drops it, we can catch that in the DragDrop event. In that events handler’s procedure, we move the column to its new location—the current mouse column—using the ColPosition property:


Private Sub MSFlexGrid1_DragDrop(Source As VB.Control, X As Single,
Y As Single)

MSFlexGrid1.ColPosition(intDragColumn) = MSFlexGrid1.MouseCol

End Sub


And that’s it. Now the user can drag and rearrange the columns in our flex grid. To see how this works, we display a database in our flex grid, as shown in Figure 12.17. To see how to do that, take a look at the next topic in this chapter where we use a Visual Basic data control (here, the database we use is the Nwind.mdb database, which comes with Visual Basic). When the user drags a column in our program, a special mouse pointer appears, as shown also in Figure 12.17.


Figure 12.17  Dragging a column in a flex grid.
The code for this example is located in the dragged folder on this book’s accompanying CD-ROM (note that to run this example, you must set the data control’s DatabaseName to the Nwind.mdb file on your computer, including the correct path).



Previous
Table of Contents
Next






Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.



Wyszukiwarka

Podobne podstrony:
medycyna wet 2009 nr 6 strony 399 403
403 a
39909
05 (399)
399 404
39906
399 Wycena niezakończonych usług budowlanych na koniec roku
395 399

więcej podobnych podstron