Microsoft KB Archive/88911

= How to Clear All or Part of Grid in Visual Basic =

Article ID: 88911

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Professional Toolkit for Microsoft Visual Basic programming system for Windows

-



This article was previously published under Q88911



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 = &quot;&quot;

' 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.</li></ol>

Additional query words: 1.00 2.00 3.00

Keywords: KB88911

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.