FLEX GRID CONTROL
Steps to add a flex grid control to the project:
Select Project.
- Components menu item.
- Click the controls tab in the components dialog box.
- Select the Microsoft FlexGrid Control entry in the components dialog box.
- Close the components dialog box by clicking on OK. This displays the Flex grid control tool in the toolbox.
Adding a flex grid control to project
Steps to be followed:
- Add a flex grid control to your form by using flex grid control tool which is currently present in tool box.
- You can set the flex grid's Rows and Cols by using properties window.
- You can also customize your flex grid by setting properties such as BorderStyle,Forecolor,BackColor and so on.
Working with data in flex grid control
Several Flex grid properties help us to work
with flex grid control:
- Row-The current row in a flex grid.
- Col-The current column in a flex grid.
- Rows-The total number of rows.
- Cols-The total number of columns.
- Text-The text in the cell at(Row,Col).
Setting Flex Grid Lines and border styles
You can set what types of grid lines a flex grid uses with the Grid line property:
- flexGridNone.
- flexGridFlat.
- flexGridInset.
- flexGridRaised.
BorderStyle properties
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 columns and rows you label in a flex grid are usually colored gray.
- You can set the number of label columns and rows with the Fixed Cols and Fixed Rows properties.
- We use visual basic functions Chr and Asc functions and enter text directly into the flex grid using its TextArray Properties.
Formatting Flex Grid Cells
You can format text using these properties of flex grids:
- CellFontBold
- CellFontItalic
- CellFontName
- CellFontUnderline
- CellFontStrikethrough
- CellFontSize
You can also size cells as you like using the CellWidth and RowHeight.
Sorting a Flex Grid Control
We can use the flex grid’s Sort property (at run ime).
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
Private Sub Command1_click()
MSFlexGrid1.Col=1
MSFlexGrid1.Sort=1
End Sub
Dragging columns in a flex grid control
- One of the attractive aspects of flex grid is that you can use drag-and-drop with them to let users rearrange the flex grid as they like.
- When the user presses the mouse button to start the drag operation we store the column in MouseDown event. This event is stored in flex grid’s MouseCol property.
- When the user drags the column to a new location and drops it we can catch that event in DragDrop event.
Connecting a flex grid to a database
Steps to connect a database to a flex grid:
- Add a data control,Data1,to your form by using data control tool in tool box.
- Set the data control’s DatabaseName in property window.
- Set the Data1’s RecordSource Property to the table in the database you want to work with.
- Set the flex grid’s DataSource property to the data control’s name, which is Data1 here.
The Timer Control
- The specific use of a timer control is to execute code at specific intervals.
- To use a timer,you add a timer control to your program and sets its Interval property,while the timer is enabled it creates Timer events.
- To add a timer to your program, use timer control tool in the tool box.
- The Interval can be set to values between 0 and 64,767 seconds.
Adding and initializing a timer control to a program
- You can add a timer control to your form by using a timer tool which is available in tool box.
- The timer control is invisible when the program runs so the size and location doesn’t matter.
- For initializing we use two properties they are,
- Enabled determines whether or not the timer creates Timer events.
- Interval sets the number of milliseconds between Timer events.
- Enabled :You can set Enabled property to False, which means no Timer events will occur. When you want to start the timer, you can set Enabled to True.
- The timer’s Enabled property varies from other controls Enabled property. the timer’s Enabled property makes Timer events occur or not, whereas other Enabled properties make controls accessible or inaccessible to the user.
Interval: It sets the interval between Timer events, Timer events cannot actually occur faster than 18.2 times a second.
Handling Timer events
The main event for timers is the Timer event,
and double-clicking a timer at design time creates
a handler function for that event
Sub Timer1_Timer()
End Sub
The code to be executed must be added in this
procedure. Timer events are not guaranteed to
occur.
The Communications Control
- To add this control to your program,
- Select the ProjectComponents menu item.
- Click the controls tab in the Component dialog
- box.
- Select the Microsoft Comm Control entry and
- click OK.
- The communication control tool appears in
- toolbox.
Creating a Clock Program
Creating a clock program involves following
steps:
- Create a new project with a form.
- Add a timer control,Timer1 to form using timer control tool.
- Set the timer’s Interval property to 1000.
- Add a label that covers that covers most of form and give it large font size.
Add the Timer1_Tick() event handler now:
Sub Timer1_Timer()
End Sub
When there’s a timer event is to update the clock and we use visual basic Time$ function to do so,
Sub Timer1_Timer()
Display. Caption=Time$
End Sub
Creating a Stopwatch
- Create a new project with a form.
- Add two command buttons in form named ‘START’ and ‘STOP’ .
- Add a label named ‘DISPLAY’ also add a timer control to form .
- Set its Enabled property to False .
- The first command button contains starting time using Now in a Form-wide variable named StartTime .
- We can start the by setting its Enabled property to True.
- The second command button contains code to stop timer i.e. Enabled property to False.
- Finally generate a Timer event by calculating time from start and stop time stored in both command buttons.
Read more of my Vb & Vb.Net Articles.