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.

You might also like...

Comments

ElementK Journals

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The greatest performance improvement of all is when a system goes from not-working to working.” - John Ousterhout