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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid FirstRow property

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
I have some code that changes the size of a datagrid control. When the control shrinks, I want to make sure that a row that might have been selected while the grid was larger is still visible when it is shrunk.

The documentation suggests that setting the FirstRow property to a valid bookmark (i.e. of the most recently selected row) should do the trick but I continually get an 'Invalid Bookmark' error message.

Any ideas?

Thanks in advance.
 
The bookmark property of the grid is only set to a valid bookmark if a record is selected (highlighted blue...not black).

If you do not have a valid grid bookmark, because a row isn't selected (as opposed to just marked) then you can use the bookmark property of the recordset (preferred):

DataGrid1.FirstRow=rsADO.Bookmark

Or, with the DC:
DataGrid1.FirstRow=Adodc1.Recordset.Bookmark



Or just:

DataGrid1.CurrentCellVisible=True [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thanks Cclint - I was all excited about the simplicity of your suggestion to use the CurrentCellVisible property (which I had failed to notice) but that seems to have no effect either - i.e. same symptoms.

I don't think there is any confusion over selected versus marked - I have even tried the equivalent of

DataGrid1.FirstRow = DataGrid1.SelBookmarks(0)

which also fails even though DataGrid1.SelBookmarks(0) does contain a value.

I am not using a data control and have tried the

DataGrid1.FirstRow=rsADO.Bookmark

option to no avail.

Any other ideas?
 
Please note:
1. If you step through the code it will not work!
2. Place the code in the form's resize event (will need an error handler or check the ado object creation and state first)
3. Are you sure it is not working? Are you resizing the grid when the form resizes? You may have the form redurced in size, but if the grid is not also reduced, then the cell may already be visible...to the grid though and not to the form/user.
4. If there are not enough remaining records (after the current record) to fill the grid, then the grid will not set the current row as the first row if it is still visible. You will need to do this using the row method. [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Hi again

It fails when I am not stepping through the code.

I am resizing using a command button that toggles between big & small sizes. I am definitely re-sizing the grid as well as its container (SsPanel) as both horizontal scrollbar and column headers are visible in big & small modes. Also, I have made sure that there are enough remaining records to fill the grid.

So, I'm still stumped!
 
P.S.

Out of sheer frustration, I have tried coding as follows:

DataGrid1.FirstRow = DataGrid1.FirstRow

and this also fails with 'Invalid Bookmark' - although it definitely contains a numeric value.

Does this make any sense?
 
The frustration continues.

I have tried taking out the sizing altogether and simply interrogating and assigning the FirstRow property. The grid has 75 records with 5 visible rows. It appears that the only format it will accept for the property is a two character string - it will not reject "AA" as an invalid bookmark nor will it reject "99" but it will reject "AAA", "100" and "1". In each case it ignores the value I supply and sets it to 71 - i.e. the first record that will be visible in the grid when the last 5 records on file are displayed.

I am about to give up and move to a solution using the .Scroll method.
 

What happens when you do this?:

rsADO.Bookmark = rsADO.Bookmark

If an error occurs, then what OLEDB provider are you using? [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 

And, what happens when you use:

DataGrid1.Bookmark = = rsADO.Bookmark
[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
No error on your suggested assignment.

I have found a solution using the scroll method such that, when I reduce the size of the grid, if the current row is outside the range of the new (smaller) grid, I resize then scroll forward the appropriate number of rows. Just as effective but I don't understand what was going wrong with FirstRow.

I am talking to a SQL Server database.

I would be interested to know what is going wrong here but don't want to put anybody to any unnecessary effort given that I have found a workaround. Thanks.
 
The 2nd suggested assignment also appears to work OK.
 
Also try DataGrid1.Bookmark = DataGrid1.Bookmark

There is only one bug that I am aware of concerning this and it has to do which using a server side cursor (which would not pertain here to a rs created with a provider like JET used as the data source on a DataGrid).

The Bug is corrected with the latest version of MDAC_Type.EXE 2.6

I would first make sure that VB6 SP5 was installed.

I do not have a problem with it on my system.

Other than that, I would experiment with a second provider, such as JET - client side cursor, just to see if it works. If it doesn't work, then the error is with something you are doing wrong.

Please note: The bookmark property is set when the data source is set, to the bookmark value of the recordset's records. You cannot set the bookmark to a value which you type in and think it will work correctly - it won't.

[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
That assignment also OK. I am using client side cursor, ADO 2.7 & VB SP5.

I wish I had time to explore further but, sadly, pressure is on.

I certainly understand that setting a bookmark to a literal is a dangerous and unpredictable practice but am very confused by behaviour when I do - especially with alphabetic data.
 
Better late than never - I resolved this a while back but failed to update this thread.

I ultimately achieved what I wanted by calculating how many rows lay between the minimum size of the grid (in rows) and the current row then used the DataGrid's Scroll method to Scroll that number of rows to ensure that the row in question was visible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top