Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/index.php)
-   General (http://www.xtremevbtalk.com/forumdisplay.php?f=7)
-   -   Setting # of rows in a MSFlexgrid during runtime (http://www.xtremevbtalk.com/showthread.php?t=9775)

Wargasm 08-08-2001 10: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 01: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 10: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
RSGrdInvoices.MoveFirst
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"
Else
.Text = ""
End If
.Col = .Col + 1
If Len(RSGrdInvoices.Fields("CheckNumber")) > 0 Then
.Text = RSGrdInvoices.Fields("CheckNumber")
Else
.Text = ""
End If
.Col = .Col + 1
If Val(RSGrdInvoices.Fields("AmountPaid")) > 0 Then
.Text = RSGrdInvoices.Fields("AmountPaid")
Else
.Text = ""
End If
.Col = .Col + 1
.Text = RSGrdInvoices.Fields("DatePaid") & ""
.Row = .Row + 1
End With
RSGrdInvoices.MoveNext
Loop

RSGrdInvoices.Close

End Sub

(Thanks for any advice you may have.)


Flyguy 08-23-2001 12: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 02: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 01:26 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises 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.