Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 15,386 times

Related Categories

Empty the MSFlexGrid


The MSFlexGrid control provides a great way to display records in multiple rows and columns. Often, however, you may want to display a variable number of rows or colums based on selections from the user. As a result you'll need a way to quickly clear not just the contents of the extraneous rows, but also to reduce the number of rows in the control. For instance, if the MSFlexGrid currently displayed 15 rows, and the user chooses to display only 10 at runtime, you need to delete five extra rows.

To do so, you might think to loop backwards through the rows and execute the RemoveItem method on each row. However, if you have a large number of rows to delete, using a For/Next loop could take some serious time and hang your application.

As an alternative, you can simply reduce the number of rows by resetting the control's Rows property. Normally, this property returns the total number of rows in the grid. However, you can also use it to remove rows. For instance, if your flexgrid currently contained 15 rows, and you wanted to reduce them to 10, you could simply issue the following code statement:

MSFlexGrid1.Rows = 9

Don't forget that flexgrid rows start with 0. The above example assumes that you haven't placed a header in the very first row. If so, then you could set the Rows property to 10 instead of 9 to display ten data rows. You can use the flexgrid's Cols property to delete columns in a similar manner.

© 2001 Element K Journals, a division of Element K Press LLC ("Element K"). Element K and the Element K logo are trademarks of Element K LLC

Comments