Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   General (http://www.xtremevbtalk.com/general/)
-   -   Setting # of rows in a MSFlexgrid during runtime (http://www.xtremevbtalk.com/general/9775-setting-rows-msflexgrid-runtime.html)

Wargasm 08-08-2001 11:48 AM

Setting # of rows in a MSFlexgrid during runtime
Hi Guys,
Does anyone out there know how to set the number of rows in a MSFlexgrid during run-time? It seems the only way to get it to run correctly is to set the # of rows to 1600(eventually that many rows may be needed as "invoices" are added to the database) during design-time. However when I also try to set the # of rows in run-time as well, I get an error. I only want to show the number of rows that I need, not all 1600 at first. In the code I've done something like this:

grdInvoices.rows = rsInoices.Recordcount +1

- the "1" is for the fixed "Header Row"

Thanks in advance!

sethindeed 08-08-2001 02:23 PM

Re: Setting # of rows in a MSFlexgrid during runtime
There are absolutly no limitations on the amount of rows you can set at RuntTime on a MSFlexGrid...it may be a problem somewhere else in your code...what the message error tells you ?

Wargasm 08-22-2001 11:23 AM

Re: Setting # of rows in a MSFlexgrid during runtime
Hi sethindeed,
As I drive trucks and I'm not always around I just noticed your reply this morning. If I set the ROWS = 0 during design time then I get Run-time error '30009' Invalid Row Value. I finally just set the ROWS = 1600 in design-time which should be enough for the next year or so. The problem is then that 1600 rows are displayed- most of them blank for now. I would rather display just the "populated' rows. below is my current code:

Private Sub sFillGrdInvoices()

' ******************************************************
' this sub-function sets the column headers and populates the grid,
' sorted by invoice number
' ******************************************************

' this will clear grid if already populated
grdInvoices.Col = 0
grdInvoices.Row = 1

' dim all variables
Dim strColumnHeaders As String
Dim strGrdInvoicesSQL As String

Set RSGrdInvoices = New ADODB.Recordset
strGrdInvoicesSQL = "SELECT * FROM Invoice ORDER BY InvoiceNumber"
RSGrdInvoices.Open strGrdInvoicesSQL, adoConnection, adOpenKeyset, adLockOptimistic

' set column headers.
strColumnHeaders = "<Invoice#|<Customer|<Theater|<Amount|<Date|<Month|& lt;Year|<Paid|<Check Number|<Amount Paid|<Date Paid"
grdInvoices.FormatString = strColumnHeaders

' fill the rest of the grid
Do Until RSGrdInvoices.EOF
With grdInvoices
.Col = 0
.ColWidth(0) = 720
.Text = RSGrdInvoices.Fields("InvoiceNumber")
.Col = .Col + 1
.ColWidth(1) = 1882
.Text = RSGrdInvoices.Fields("CustomerName")
.Col = .Col + 1
.ColWidth(2) = 2000
.Text = RSGrdInvoices.Fields("TheaterName1")
.Col = .Col + 1
.ColWidth(3) = 720
.Text = Format(RSGrdInvoices.Fields("TotalDue"), "CURRENCY")

.Col = .Col + 1
.ColWidth(4) = 675
.Text = RSGrdInvoices.Fields("InvoiceDate")
.Col = .Col + 1
.Text = RSGrdInvoices.Fields("Month")
.Col = .Col + 1
.ColWidth(5) = 850
.Text = RSGrdInvoices.Fields("Year")
.Col = .Col + 1
.ColWidth(6) = 450
If RSGrdInvoices.Fields("Paid") = True Then
.Text = "Paid"
.Text = ""
End If
.Col = .Col + 1
If Len(RSGrdInvoices.Fields("CheckNumber")) > 0 Then
.Text = RSGrdInvoices.Fields("CheckNumber")
.Text = ""
End If
.Col = .Col + 1
If Val(RSGrdInvoices.Fields("AmountPaid")) > 0 Then
.Text = RSGrdInvoices.Fields("AmountPaid")
.Text = ""
End If
.Col = .Col + 1
.Text = RSGrdInvoices.Fields("DatePaid") & ""
.Row = .Row + 1
End With


End Sub

(Thanks for any advice you may have.)

Flyguy 08-23-2001 01:01 PM

Re: Setting # of rows in a MSFlexgrid during runtime
You said the number of rows was set to 0 in design time.

your code:
' this will clear grid if already populated
grdInvoices.Col = 0
grdInvoices.Row = 1
The line "grdInvoices.Row = 1" will cause the error, because you don't have any rows so you can't set the row property to 1

If you want to clear the grid use:
grdInvoices.Rows = 0

You do start with a Header so set it to 1
grdInvoices.Rows = 1

And use the header format string

In the DO UNTIL loop
place this statement on the first line:
grdInvoices.Rows = grdInvoices.Rows + 1

And you end up with all the rows needed.

Thinker 08-23-2001 03:29 PM

Re: Setting # of rows in a MSFlexgrid during runtime
My advice is you get rid of that MSFlexGrid and replace it with the
MSHFlexGrid. It will allow you to set its recordset property = your
recordset at runtime and will dynamically bind and populate your grid.

I think therefore I am... sometimes right. [img]images/icons/wink.gif[/img]

All times are GMT -6. The time now is 10:44 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.