Hi,

I have used a Flex Grid control in displaying a set of records from the MS ACCESS database (back end) with the means of VB6 code (front end).

In my database i have 9 records and the flex grid control has been deisgned at design time with 7 rows.
I have full- compiled my code and seen that NO syntax errors exist.

ISSUE:
At runtime, when the grid control retrieves the 9 records from the db, an error is popped up: "Invalid Row Value".
I have tested and seen that if there are 7 records in db, then no errors occur. But, at runtime, if the records queried, exceed the no of rows in the grid control, designed at design time, then this error occurs. And even no vertical scrollbar appears.

----------------------------------------------------------------------
Visual Basic 6 code:
----------------------------------------------------------------------
''''For loop counters for each cell. ex: (0,0) -> (ROW, COL)
Dim dblRow_ISBN As Double, dblCol_ISBN As Double

'''''coding for the DATAGRID control to populate itself with records
'--------------------------------------------------------------
-------------------------------------------------------------
Call Connect_Database ''''database connection code

recset.Open "select ISBN, [Book Title], Author, CoAuthor1, CoAuthor2 " _
& "from " & strTable & " " _
& "order by " & field & ""
'-------------------------------------------------------------------

If (recset.RecordCount <> 0) Then
For dblRow_ISBN = 1 To recset.RecordCount
dblCol_ISBN = 0

grdISBN.Row = dblRow_ISBN 'ROW will be same for all the 5 columns

grdISBN.Col = dblCol_ISBN
grdISBN.Text = recset.Fields("ISBN")
grdISBN.Col = dblCol_ISBN + 1
grdISBN.Text = recset.Fields("Book Title")
grdISBN.Col = dblCol_ISBN + 2
grdISBN.Text = recset.Fields("Author")
grdISBN.Col = dblCol_ISBN + 3
grdISBN.Text = recset.Fields("CoAuthor1")
grdISBN.Col = dblCol_ISBN + 4
grdISBN.Text = recset.Fields("CoAuthor2")

recset.MoveNext
Next dblRow_ISBN
End If
dbconn.Close 'closes database connection

====================================================

Who can really help me on this ? His help will be definately appreciated.
Awaiting reply....

Recommended Answers

All 5 Replies

I recommend using something other than the flexgrid. I use the listview all the time. Setup the listview like below and add items.

With lvList
    .View = lvwReport
    .FullRowSelect = True
    .HideColumnHeaders = False
    .HideSelection = False
    
    .ColumnHeaders.Add 1, , "Col 1"
    .ColumnHeaders.Add 2, , "Col 2"
    .ColumnHeaders.Add 3, , "Col 3"

End With

Dim irows As Integer

For irows = 0 To 10
    lvList.ListItems.Add lvList.ListItems.Count + 1, , "Data: " & CStr(irows)
    lvList.ListItems(lvList.ListItems.Count).ListSubItems.Add 1, , "Sub data 1: " & CStr(irows)
    lvList.ListItems(lvList.ListItems.Count).ListSubItems.Add 2, , "Sub data 2: " & CStr(irows)
Next

Hi..buddy,

Thanks a lot for ur willingness to help out. And give me an extra edge with a control that i have never used: the ListView, even though I have marked this post as RESOLVED.
I will surely refer to ur advice in future, when i need to display records in a manner such as in a grid.


QUESTION:
=======
I did not understand 2 code lines. Could u pls explain their syntax/pattern for parametres from ur code snippet ??

************************************************************
lvList.ListItems.Add lvList.ListItems.Count + 1, , "Data: " & CStr(irows)
************************************************************

***********************************************************
lvList.ListItems(lvList.ListItems.Count).ListSubItems.Add 1, , "Sub data 1: " & CStr(irows)
***********************************************************

And why do u recommend the ListView , instead of the FLEX GRID ?
Becoz, as per after going thru ur code, i am seeing that the ListView cannot draw the vertical & horizontal lines like a grid control. Hence this can lead to visual ambiguity for the reader, when the list is heavily populated with database records.
And i feel that the code for the grid that i have stated is much more simple requiring lesser variety of properties, arguments & methods.
Infact one does not need to know any syntax to code the Grid control, just a logical visual sequence of steps. But in ur List View, i am having problems to understand the code, becoz i have to learn the new format of the properties & argument patterns used.

Please provide a more solid and really simple point to make someone shift from coding the grid to using the ListView in future....
I am not being rude. But lets make it really worthwile to move to another probably better control (fingers crossed)
Awaiting ur techies suggestions....

I recommend using something other than the flexgrid. I use the listview all the time. Setup the listview like below and add items.

With lvList
    .View = lvwReport
    .FullRowSelect = True
    .HideColumnHeaders = False
    .HideSelection = False
    
    .ColumnHeaders.Add 1, , "Col 1"
    .ColumnHeaders.Add 2, , "Col 2"
    .ColumnHeaders.Add 3, , "Col 3"

End With

Dim irows As Integer

For irows = 0 To 10
    lvList.ListItems.Add lvList.ListItems.Count + 1, , "Data: " & CStr(irows)
    lvList.ListItems(lvList.ListItems.Count).ListSubItems.Add 1, , "Sub data 1: " & CStr(irows)
    lvList.ListItems(lvList.ListItems.Count).ListSubItems.Add 2, , "Sub data 2: " & CStr(irows)
Next
'************************************************************
lvList.ListItems.Add lvList.ListItems.Count + 1, , "Data: " & CStr(irows)
'************************************************************
 
'The "lvList.ListItems.Add" is adding another row to the listview.
'The first argument is the index to add the row.  (I'm using the next row in the listview as my index)
'The second argument is optional and I never really use it anyways.
'The third is the first cell in that row that will hold "Data: " & Cstr(irows)

'***********************************************************
lvList.ListItems(lvList.ListItems.Count).ListSubItems.Add 1, , "Sub data 1: " & CStr(irows) 
'***********************************************************

'The  "lvList.ListItems(lvList.ListItems.Count).ListSubItems.Add" adds subitems to the row we just made above. The "(lvList.ListItems.Count) just states to make the subitems in the very last row of the listview.
'The "ListSubItems.Add" adds the subitem
'The first argument is the index of the subitem.  In the first one it is the 1st index (2nd column) and the second is the 2nd index (3rd column).
'The second argument is optional and i don't use that either.
'The third argument is the data to put in the subitem cell.

Why would you want to switch? Well the Listview has alot of functionality to it once you learn it. You can make it look alot better and modify the cell data and then even update a database based on the modification.

The suggestion is my opinion on using the Listview over the Flexgrid cause like you I use to use the Flexgrid until I ran across the ListView and I was like wow this control is great, I'm going to use this from now on.

So if you don't feel comfortable learning a new control then don't but I had to share my opinion. Which is only that, my opinion. I hope you enjoy using either.

Sorry, I forgot to post that the ListView can get the grid lines by going to the properties and selecting "GridLines" and change the value to True. If you Right-Click on the control and click Properties you will see a slew of options. Go ahead and play around with them. Its the only way to learn. :D

Thanks a lot for ur code and willingness to help.

I have now almost learnt ur newly anticipated ListView control....BRAVO!!
I have attached my newly learnt knowledge as a zip file. Please see it and tell me if i am on the right track with the listView control (5 KB).


But I still cannot understand this line, mainly the bracketed part only:

lvSubjects.ListItems(lvSubjects.ListItems.Count).ListSubItems.Add 1, , "QWE"

I know that the above line is used for referring to code details for the subdata item. Please give me a better concept of the bracketed part.

Do u also know the deployment stuff of Crystal Report 11, then i can tell u my new issue on that. Maybe u could solve it....
Awaiting ur response....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.