Link to home
Start Free TrialLog in
Avatar of mawe
mawe

asked on

Number of FlexGrid rows

In my grid I have one fixed row. I have to have at least two two ordinary rows by default otherwise I receive a "invalid Row Value" error. This results in an extra row as row number one when I fill the grid from a database.
How can I overcome this? How can I get the grid to be filled from the first row?
Avatar of mdougan
mdougan
Flag of United States of America image

You may have some code that is referencing a row before you are creating it.  It would help if you included all of the code you use to fill your grid.  Here are some guidlines I use when filling a grid.

I use one fixed row, where I put the headings.  If possible, I set the headings at design time, but if not possible, I make sure that I give the grid one row at design time, and perhaps in my code, at form_load time I'll set the grid's formatstring property to the column headers.

MyGrid.FormatString = "Rec Number|First Name   |Last Name    "

Then, if I'm filling the grid manually, I'll have some code like this:
.
while not rs.EOF
   MyGrid.Rows = MyGrid.Rows + 1
   i = MyGrrid.Rows - 1
   MyGrid.TextMatrix(i, 0) = rs("RecNum")
   MyGrid.TextMatrix(i, 1) = rs("FirstName")
   MyGrid.TextMatrix(i, 2) = rs("LastName")
   rs.MoveNext
Wend

By adding one to the Rows property before trying to put data into it, I make sure I have a valid row.  Also, keep in mind that the row numbers start at 0 and go to Rows - 1.  So, row 1 actually has an index of 0, and the last row of the grid has an index of Rows - 1.  Usually, getting "Invalid Row Value" has something to do with this.  Also, if you are keeping your headings in the fixed row (row index 0) then you can clear your grid out by saying MyGrid.Rows = 1.

MD
Avatar of mawe
mawe

ASKER

This is the code I use to fill my grid from a database. The problem is that it starts filling from the second row in the grid.
 
        Do While Not MyDataBase.Recordset.EOF
            MyFlexGrid.AddItem ( _
            MyDataBase.Recordset(0) & Chr(9) & _
            MyDataBase.Recordset(1) & Chr(9) & _
            MyDataBase.Recordset(2) & Chr(9) & _
            MyDataBase.Recordset(3) & Chr(9) & _
            MyDataBase.Recordset(4))
            MyDataBase.Recordset.MoveNext
        Loop
Delete the seconde line at the end of the loop:

MyFlexGrid.RemoveItem 2
AddItem will always add a row to the bottom of the grid for you.  So, your problem is that you are starting out with a blank row.  You shouldn't have to do that.  When exactly is it that you get the Invalid Row Value message?  Does your fixed row contain column headers, or are you trying to put data there?  You should be able to set the number of rows for your grid at 1, at design time.  Then fill the headers using the formatstring either at design time or at run time, then your additems should work without giving you that message.

MD
Avatar of mawe

ASKER

I actually succeeded in removing the first blank row. The key to the success was to set the number of rows to 1. This didn't (for some reason) work on the property page but had to be done in the code. Thanks for the help!

just set the ROWS property of the flexgrid before
fill the grid with data
just set the ROWS property of the flexgrid to 1 before
fill in the grid with data
You might have had fixed rows and the no of rows should be atleast 1 greater than the no of fixed rows. This may be a possible reason why it dint work in the property page.
ASKER CERTIFIED SOLUTION
Avatar of RamRam111798
RamRam111798

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you don't want the empty row(If you get 0 rows).
add this line after assigning the clip.

if iNumofRows = 0 then
   Me.msEstSummary(1).Rows =   Me.msEstSummary(1).Rows-1
end if