Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A flaw in the datagrid control?

Status
Not open for further replies.

xinyin

Programmer
Jan 16, 2003
81
HK
Hi all,
There is a "FirstRow" property in datagrid. According to the documents, by setting this property in a way like
" [Datagrid].FirstRow = 5] "
the datagrid will roll to a certain row, in this case, 5.
But what I get is a run-time error 6149 "Invalid Bookmark"?
Is this is a flaw in the design of datagrid?
 
You have to actually move the recordset to the record you want to display as the first row, save the bookmark for that row and assign the bookmark to the FirstRow property:

Dim BkMk As Long

rs.Move 5

BkMk = rs.Bookmark

DataGrid1.FirstRow = BkMk



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Hi jebenson,
I tried your code but it still gives me run-time error 6149 "Invalid Bookmark". I used someone else's machine and had the same result. Did that run properly in your machine?
 
Yes, it did.

After some further testing I have been able to replicate the error you are getting. If I do this:

DataGrid1.FirstRow = 5

I get a type mismatch error. If I do this:

DataGrid1.FirstRow = "5", I get the invalid bookmark error you are getting. If I do this:

Dim BkMk As Long

BkMk = 5

DataGrid1.FirstRow = BkMk

everything works fine, with no error message. So, my first post was in error, you do not need to move the recordset and copy the bookmark, you just need to pass a Long variable to the FirstRow property.

Could you show your code where you create your connection object, and where you create and populate your recordset?


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
My situation is slightly different from yours - no matter I type DataGrid1.FirstRow = 5 or DataGrid1.FirstRow = "5" I get invalid bookmark error but never get type mismatch error (it's error anyways...)

Here is my code of the connection part.

'Define the Connection and Recordset in the public area of the form (= not inside any sub), so that any sub in this form can use them.
'---------------------------------------------
Public WithEvents vConnect As ADODB.Connection
Public vSQL As String
Public vRset As ADODB.Recordset
'---------------------------------------------

'I put the connecting part in Form_Load(), the recordset gets its source data from an Access database.
'-----------------------------------------------------------------
Set vConnect = New ADODB.Connection
On Error GoTo 0
With vConnect
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = [The path to the Access database]
.CursorLocation = adUseClient
.Open
End With

vSQL = "Select * From [Table name] ORDER BY [Field name] ASC"
Set vRset = New ADODB.Recordset
With vRset
.CursorLocation = adUseClient
.ActiveConnection = vConnect
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open vSQL
End With
'-----------------------------------------------------------------
 
Well, the connection and recordset code looks fine. I thought maybe there might be an issue with the cursor location, but that doesn't seem to be it. Hmmmm...I'm stumped.

Sorry I couldn't help you find a solution to this.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
I have been able to replicate the error xinyin is getting using jebenson's code.

How are you both populating your respective datagrids?? Maybe that might have something to do with it?

Cheers

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
Here's what I'm doing:

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset

Dim conn As ADODB.Connection
Set conn = New ADODB.Connection

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Temp\USAS MHX.mdb;Persist Security Info=False"
conn.CursorLocation = adUseClient


If conn.State = adStateOpen Then conn.Close

conn.Open

rs.ActiveConnection = conn
rs.CursorLocation = adUseClient
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic

rs.Open "select * from tblcashactivity"

Set DataGrid1.DataSource = rs


And then comes all of the bookmark stuff.

I've tested this with ADO 2.6, 2.7 and 2.8.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Trying the code you (and xinyin) provided using AD) 2.7 I am getting the exact same problem (invalid bookmark) as xinyin. Hmmm....

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
Do you think there is something to do with the patch files / service packs provided by microsoft? The technician guy in the office told me that the computer I am using now had installed SOME VB6 service packs (probably SP6, but not SP5) downloaded from the MSDN site.
 
Hi jebenson,
There is one thing I really want to know about FirstRow, but since my computer cannot handle this, so could you please do a test for me? Here is the test: For example, if you have 10 records but the datagrid is only 5 rows tall (displaying maximum 5 records a time), if you set FirstRow = 1 ~ 6 there is no problem - that record will be at the top of the datagrid. But if you set FirstRow = 10... I wonder if datagrid will follow your command and put record #10 at the top position, or just got stuck at record #6? This is because I think that datagrid does not like to have blank rows, if it lets the last record (#10) to be at the top row, then there will be 4-rows-tall blank area under it, and I don't think this is likely to happen.
 
I hit a similar problem a while back.

thread222-465580 may help.
 
Thanks Glasgow. Now I simply give up firstrow and use scroll instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top