How to Clear All or Part of Grid in Visual Basic
ID: Q88911
|
The information in this article applies to:
-
Microsoft Visual Basic Professional Edition for Windows, versions 2.0, 3.0
-
Microsoft Professional Toolkit for Microsoft Visual Basic programming system for Windows, version 1.0
SUMMARY
You can clear all or part of a grid by first selecting the region to clear
using the SelStartCol, SelStartRow, SelEndCol, and SelEndRow properties,
and then clearing the region by assigning a null string to the Clip
property.
MORE INFORMATION
The example below demonstrates how to clear all the non-fixed cells of
a grid.
Step-by-Step Example
- Start Visual Basic or from the File menu, choose New Project (ALT, F, N)
if Visual Basic is already running. Form1 is created by default.
- From the File menu, choose Add File, and select GRID.VBX. The Grid
tool appears in the Toolbox. (This step is automatic in version 2.0.)
- Place a grid (Grid1) on Form1.
- Set the Grid1 property Cols to 4, and Rows to 4. Size the grid so
that you can see all the cells.
- Enter the following code into the Form1 Load event procedure:
Sub Form_Load ()
' Load some data into the grid.
For i% = Grid1.FixedCols To Grid1.Cols - 1
For j% = Grid1.FixedRows To Grid1.Rows - 1
Grid1.Col = i%
Grid1.Row = j%
Grid1.Text = Format$(i% + j%)
Next
Next
End Sub
- Enter the following code into the Form1 Click event procedure:
Sub Form_Click ()
' Select all non-fixed grid cells.
Grid1.SelStartCol = Grid1.FixedCols
Grid1.SelStartRow = Grid1.FixedRows
Grid1.SelEndCol = Grid1.Cols - 1
Grid1.SelEndRow = Grid1.Rows - 1
' Clear the cells.
Grid1.Clip = ""
' Clean up the grid.
Grid1.Col = Grid1.FixedCols
Grid1.Row = Grid1.FixedRows
Grid1.SelEndCol = Grid1.SelStartCol
Grid1.SelEndRow = Grid1.SelStartRow
End Sub
- Press F5 to run the program. The grid appears with numbers in the
cells. Click Form1. The grid is cleared.
Additional query words:
1.00 2.00 3.00
Keywords :
Version :
Platform :
Issue type :
|