Saving focused row on EnhancedList requery


Author
Message
Andria Jensen
Andria Jensen
Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)
Group: Forum Members
Posts: 336, Visits: 497
I'm doing a requery of an EnhancedList after making some updates to the BO that I have bound to it.  After the requery the focus always jumps to the top of the list.  Is there a way to keep it from doing this and have the focus make sense.  i.e. Focus on a newly added row, focus on the next if one is deleted, and keep current focus on an edit?
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
I am sure that there is but you will be better served looking at the DevExpress help.  Off the top of my head I do not know and I would have to look into this myself.  But you should be able to set the focused row and then call a method like EnsureVisible to make sure that it is active.  You can place all of the code to do this in the AfterRequery method.  Also, the control to look at in DevExpresss would be a GridView.  This is the type of view used inside of the grid.  You can access it thought the MainView property on the grid and just CType it as a GridView.
Andria Jensen
Andria Jensen
Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)
Group: Forum Members
Posts: 336, Visits: 497

I am doing this:

Dim SaveFocusedRow As Object
Dim RowHandle As Integer

SaveFocusedRow = gvHdr.GetRow(gvHdr.FocusedRowHandle)

grdHdr.Requery() 

RowHandle = FindRowHandleByRowObject(gvHdr, SaveFocusedRow)

If RowHandle <> DevExpress.XtraGrid.GridControl.InvalidRowHandle Then   
  gvHdr.FocusedRowHandle = RowHandle
End If

But it's not able to find the row in the list, it keeps returning back InvalidRowHandle.  I originally did go to DevExpress help and this was what I was told to do.  However, it's not working so I wasn't sure if there was something in the EnhancedList conflicting with it or something else that I could use instead.  I'll keep looking...this seems like it should be easy but it's proving to be rather difficult.

The FindRowHandleByRowObject Function is defined as below:

Private Function FindRowHandleByRowObject(ByVal view As DevExpress.XtraGrid.Views.Grid.GridView, ByVal row As Object) As Integer

  If Not row Is Nothing Then
    For i as Integer = 0 To view.DataRowCount - 1
      If row.Equals(view.GetRow(i)) Then        Return i 
    Next
  End If
  Return DevExpress.XtraGrid.GridControl.InvalidRowHandle

End Function


Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
It is because you are saving off a row instance.  When the grid is re-populated it creates new rows and makes the row reference you have obselete.  You need to save off the index, because that should not change.
Andria Jensen
Andria Jensen
Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)
Group: Forum Members
Posts: 336, Visits: 497
Something that may help me...what is actually under the Requery?  It appears that it is just creating a data table from the populated BO and setting the DataSource property.  Is there anything else going on?  I can't exactly ask DevExpress why my focus changes on Requery because they don't know what I'm talking about there.
Andria Jensen
Andria Jensen
Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)
Group: Forum Members
Posts: 336, Visits: 497
But wouldn't the index change if my list is sorted and something gets added into the middle of it?  This is fine for an edit where i want the focus to stay on the same one and nothing is added or deleted, but that won't work for new rows or for deletes.
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Well, store off the PK of the row.  When you setup the PopulationDataSourceSettings, you can provide the field that will be stored in the Tag property of each row.  Get the PK value and then iterate through the rows when repopulated and set the item that has a matching PK.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search