Solved

Number of FlexGrid rows

Posted on 1999-01-12
10
725 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
Comment Utility
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
Comment Utility
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
Comment Utility
Delete the seconde line at the end of the loop:

MyFlexGrid.RemoveItem 2
0
 
LVL 18

Expert Comment

by:mdougan
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Expert Comment

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

Expert Comment

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

Expert Comment

by:Bhargava
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now