Updating datagrid with requery, datagrid goes to top

Updating datagrid with requery, datagrid goes to top

Post by Sukesh Hooga » Tue, 29 Oct 2002 22:52:48



Dennis

Before requery, capture the book mark of the row in SomeBookMark  and then
after requery

DataGrid.FirstRow=SomeBookMark

Sukesh


Quote:> Hi,

> For refreshing my data in the datagrid, I use the requery-property.
> When I do this, I set the absoluteposition of the ado recordset back to
the
> absoluteposition it was before the requery.
> When the datagrid is scrollable. The grid doesn't comes back to the state
it
> has before the requery.

> I think I must use the firstrow-property. (Thisone indicates or sets the
> first visible row)
> But when I want to set the firstrow-property, it goes wrong.

> How do I use this property?

> Greetz,

> Dennis

 
 
 

Updating datagrid with requery, datagrid goes to top

Post by Haral » Tue, 29 Oct 2002 22:30:42


Hello !!

Try this !

Dim rec As New ADODB.Recordset

Private Sub Form_Initialize()
   Dim SQL As String

   ' nur Rezepte anzeigen, die nicht als versteckt markiert sind (Hide =
false)
   'SQL = "SELECT RNr, RBez, RClass, KdCode FROM tabRezepte WHERE
(Hide=false) ORDER BY RNr DESC"
   ' alle Rezepte werden ausgewaehlt, (Hide = false)-Auswahl wird erst bei
Filter getroffen
   SQL = "SELECT RNr, RBez, RClass, KdCode, Hide FROM tabRezepte ORDER BY
RNr DESC"

   With rec
      Set .ActiveConnection = conDBVSG
      .LockType = adLockOptimistic
      .CursorType = adOpenKeyset
      .CursorLocation = adUseClient
      .Source = SQL
   End With
end sub
.....
public sub .....
   Dim BookMark

   frmRezeptDaten.Show vbModal, Me        ' Formular fr RezeptDaten ?ffnen
   BookMark = rec.BookMark
   rec.Requery
   rec.BookMark = BookMark
   RezeptListe_Refresh                    ' Rezeptliste, Datagrid
aktualisieren
end sub

Private Sub RezeptListe_Refresh()

   With DataGrid1                            ' DataGrid
      '   .Refresh         ' not OK

      Set .DataSource = rec       ' It's OK
   End With
   ' Spaltenberschriften und -Breiten von Hidden-Label bernehmen
   AutoSizeGridByLabel DataGrid1, lblDataGrid, , False
   txtAnzRec.Text = rec.RecordCount
End Sub

Best Regards

Harald



Quote:> Hi,

> For refreshing my data in the datagrid, I use the requery-property.
> When I do this, I set the absoluteposition of the ado recordset back to
the
> absoluteposition it was before the requery.
> When the datagrid is scrollable. The grid doesn't comes back to the state
it
> has before the requery.

> I think I must use the firstrow-property. (Thisone indicates or sets the
> first visible row)
> But when I want to set the firstrow-property, it goes wrong.

> How do I use this property?

> Greetz,

> Dennis


 
 
 

Updating datagrid with requery, datagrid goes to top

Post by Dennis Snoey » Tue, 29 Oct 2002 20:31:13


Hi,

For refreshing my data in the datagrid, I use the requery-property.
When I do this, I set the absoluteposition of the ado recordset back to the
absoluteposition it was before the requery.
When the datagrid is scrollable. The grid doesn't comes back to the state it
has before the requery.

I think I must use the firstrow-property. (Thisone indicates or sets the
first visible row)
But when I want to set the firstrow-property, it goes wrong.

How do I use this property?

Greetz,

Dennis

 
 
 

Updating datagrid with requery, datagrid goes to top

Post by Dennis Snoey » Wed, 30 Oct 2002 00:15:30


Nop,

The grid doesn't stay on the same record. The active record becomes the
firstrow. While it isn't the firstrow but the 3th or something.
Before I requery I want to now how the datagrid (with vertical scroll-bar)
placed the recordset in the grid. (firstrow property)

Dennis



> Hello !!

> Try this !

> Dim rec As New ADODB.Recordset

> Private Sub Form_Initialize()
>    Dim SQL As String

>    ' nur Rezepte anzeigen, die nicht als versteckt markiert sind (Hide =
> false)
>    'SQL = "SELECT RNr, RBez, RClass, KdCode FROM tabRezepte WHERE
> (Hide=false) ORDER BY RNr DESC"
>    ' alle Rezepte werden ausgewaehlt, (Hide = false)-Auswahl wird erst bei
> Filter getroffen
>    SQL = "SELECT RNr, RBez, RClass, KdCode, Hide FROM tabRezepte ORDER BY
> RNr DESC"

>    With rec
>       Set .ActiveConnection = conDBVSG
>       .LockType = adLockOptimistic
>       .CursorType = adOpenKeyset
>       .CursorLocation = adUseClient
>       .Source = SQL
>    End With
> end sub
> .....
> public sub .....
>    Dim BookMark

>    frmRezeptDaten.Show vbModal, Me        ' Formular fr RezeptDaten
?ffnen
>    BookMark = rec.BookMark
>    rec.Requery
>    rec.BookMark = BookMark
>    RezeptListe_Refresh                    ' Rezeptliste, Datagrid
> aktualisieren
> end sub

> Private Sub RezeptListe_Refresh()

>    With DataGrid1                            ' DataGrid
>       '   .Refresh         ' not OK

>       Set .DataSource = rec       ' It's OK
>    End With
>    ' Spaltenberschriften und -Breiten von Hidden-Label bernehmen
>    AutoSizeGridByLabel DataGrid1, lblDataGrid, , False
>    txtAnzRec.Text = rec.RecordCount
> End Sub

> Best Regards

> Harald



> > Hi,

> > For refreshing my data in the datagrid, I use the requery-property.
> > When I do this, I set the absoluteposition of the ado recordset back to
> the
> > absoluteposition it was before the requery.
> > When the datagrid is scrollable. The grid doesn't comes back to the
state
> it
> > has before the requery.

> > I think I must use the firstrow-property. (Thisone indicates or sets the
> > first visible row)
> > But when I want to set the firstrow-property, it goes wrong.

> > How do I use this property?

> > Greetz,

> > Dennis

 
 
 

Updating datagrid with requery, datagrid goes to top

Post by Dennis Snoey » Tue, 29 Oct 2002 23:50:41


Ok,

How do I capture?



Quote:> Dennis

> Before requery, capture the book mark of the row in SomeBookMark  and then
> after requery

> DataGrid.FirstRow=SomeBookMark

This is where it goes wrong.
But what comes before it (before the requery)

> Sukesh



> > Hi,

> > For refreshing my data in the datagrid, I use the requery-property.
> > When I do this, I set the absoluteposition of the ado recordset back to
> the
> > absoluteposition it was before the requery.
> > When the datagrid is scrollable. The grid doesn't comes back to the
state
> it
> > has before the requery.

> > I think I must use the firstrow-property. (Thisone indicates or sets the
> > first visible row)
> > But when I want to set the firstrow-property, it goes wrong.

> > How do I use this property?

> > Greetz,

> > Dennis

 
 
 

Updating datagrid with requery, datagrid goes to top

Post by Dennis Snoey » Wed, 30 Oct 2002 18:48:12


Ok,

How do I capture?



Quote:> Dennis

> Before requery, capture the book mark of the row in SomeBookMark  and then
> after requery

> DataGrid.FirstRow=SomeBookMark

This is where it goes wrong.
But what comes before it (before the requery)
> Sukesh



> > Hi,

> > For refreshing my data in the datagrid, I use the requery-property.
> > When I do this, I set the absoluteposition of the ado recordset back to
> > the
> > absoluteposition it was before the requery.
> > When the datagrid is scrollable. The grid doesn't comes back to the
> >  state it has before the requery.

> > I think I must use the firstrow-property. (Thisone indicates or sets the
> > first visible row)
> > But when I want to set the firstrow-property, it goes wrong.

> > How do I use this property?

> > Greetz,

> > Dennis

 
 
 

Updating datagrid with requery, datagrid goes to top

Post by Sukesh Hooga » Wed, 30 Oct 2002 23:16:02


Dennis

Try

Dim lngNbr As Long

Before requery

lngNbr=Datagrid.FirstRow

After you run requery command

Datagrid.Scroll 0,lngNbr

Sukesh


> Ok,

> How do I capture?



> > Dennis

> > Before requery, capture the book mark of the row in SomeBookMark  and
then
> > after requery

> > DataGrid.FirstRow=SomeBookMark

> This is where it goes wrong.
> But what comes before it (before the requery)

> > Sukesh



> > > Hi,

> > > For refreshing my data in the datagrid, I use the requery-property.
> > > When I do this, I set the absoluteposition of the ado recordset back
to
> > the
> > > absoluteposition it was before the requery.
> > > When the datagrid is scrollable. The grid doesn't comes back to the
> state
> > it
> > > has before the requery.

> > > I think I must use the firstrow-property. (Thisone indicates or sets
the
> > > first visible row)
> > > But when I want to set the firstrow-property, it goes wrong.

> > > How do I use this property?

> > > Greetz,

> > > Dennis

 
 
 

1. How do I requery a datagrid

Hello!

I have a datagrid based on a recordset that has a SQL as source. The SQL is
composed of 4 SELECT put together with UNION, which select from the same
table, leaving out records where ShowBoolean is false. The Recordset is
global to the form the datagrid is on.
Showing the datagrid works fine.
On my form there is a button to delete an entry by setting its ShowBoolean
to false via executing a SQL against a connection object.
It seems setting ShowBoolean to false works fine. When I get the value of
the changed record right after changing it by another connection it is
actually changed to false.
I then requery the RS the datagrid is based on. When I 'delete' the first
record the datagrid changes. When I delete another one nothing happens, when
I delete the same one again, it disappears, when I delete a different one,
both disappear.
I think it has something to do with the datagrid not refreshing its data
correctly, so I tried several methods, like rebinding it or setting its
datasource to nothing and then back to the requeried RS, but it doesn't
help.

Is there another way to do it?

Thanks
Jan

2. tools for dba administration and performance monitoring

3. Delete Then "Refresh/Requery" DataGrid

4. Want Info on Apple's DAL (CL/1)

5. label.requery from datagrid

6. Number of SQL statements per second with ADO2.1

7. Copy from Datagrid to datagrid

8. How to restrict trigger to current row?

9. Going Nuts with DataGrid

10. Datagrid goes blank after adFilterNone applied

11. SQL: How to update a client application (datagrid) when something changes in a table

12. DataGrid update question

13. Datagrid problem - can't update