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?
maweAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
RamRam111798Connect With a Mentor Commented:
Try my code.Pass the data and number of rows to the following procedure.That works on my App.

Private Sub Tab2_populate_Grid(sDetailBuffer As String, iNumRows As Integer)
        dim fsHeader as string
        Me.msEstSummary(1).Font.Bold = True
        fsHeader = vbNullString
        Call Tab2_Grid_Header(fsHeader)
        Me.msEstSummary(1).Redraw = False
        If iNumRows <> 0 Then
            Me.msEstSummary(1).Rows = iNumRows + 1
        Else
            Me.msEstSummary(1).Rows = iNumRows + 2
        End If
        Me.msEstSummary(1).Cols = EstNoOfCols 'constant                                                                           'NoOfRows
        Me.msEstSummary(1).FixedRows = 1
        Me.msEstSummary(1).FixedCols = 0
       
        Me.msEstSummary(1).Row = 0
        Me.msEstSummary(1).Col = 0
        Me.msEstSummary(1).RowSel = iNumRows
        Me.msEstSummary(1).ColSel = EstNoOfCols - 1
       
        Me.msEstSummary(1).Clip = fsHeader & sDetailBuffer
        Me.msEstSummary(1).Redraw = True
       
End Sub
Private Sub Tab2_Grid_Header(fsHeader As String)
 fsHeader = "Item ID" & vbTab & _
            "Item Description" & vbTab & _
            "PC" & vbTab & _
            "UOM" & vbcr
           
End Sub

0
 
mdouganCommented:
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
0
 
maweAuthor Commented:
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
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
chabaudCommented:
Delete the seconde line at the end of the loop:

MyFlexGrid.RemoveItem 2
0
 
mdouganCommented:
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
0
 
maweAuthor Commented:
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!

0
 
kianweiCommented:
just set the ROWS property of the flexgrid before
fill the grid with data
0
 
kianweiCommented:
just set the ROWS property of the flexgrid to 1 before
fill in the grid with data
0
 
BhargavaCommented:
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.
0
 
RamRam111798Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.