Solved

Number of FlexGrid rows

Posted on 1999-01-12
10
730 Views
Last Modified: 2013-12-25
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?
0
Comment
Question by:mawe
  • 2
  • 2
  • 2
  • +3
10 Comments
 
LVL 18

Expert Comment

by:mdougan
ID: 1489592
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
 

Author Comment

by:mawe
ID: 1489593
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
 
LVL 4

Expert Comment

by:chabaud
ID: 1489594
Delete the seconde line at the end of the loop:

MyFlexGrid.RemoveItem 2
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
LVL 18

Expert Comment

by:mdougan
ID: 1489595
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
 

Author Comment

by:mawe
ID: 1489596
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
 

Expert Comment

by:kianwei
ID: 1489597
just set the ROWS property of the flexgrid before
fill the grid with data
0
 

Expert Comment

by:kianwei
ID: 1489598
just set the ROWS property of the flexgrid to 1 before
fill in the grid with data
0
 
LVL 2

Expert Comment

by:Bhargava
ID: 1489599
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
 
LVL 1

Accepted Solution

by:
RamRam111798 earned 100 total points
ID: 1489600
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
 
LVL 1

Expert Comment

by:RamRam111798
ID: 1489601
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question