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

Datagrid: Return to Row with Focus After Refresh

Status
Not open for further replies.

DerPflug

Programmer
Mar 28, 2002
153
US
I'm using an Infragistics Wingrid but I'm assuming (maybe incorrectly) that it behaves the same as the MS datagrid in this context. My dilemma is that I have a Wingrid that acts as a readonly snapshot of the data in my database. The underlying datasource for the grid is never updated by the grid. I have a timer that fires a stored procedure that queries the database every 10 seconds to get any updates. The grid is updated fine when I call:

Code:
myGrid.DataSource = dsMyDataSet

However, if the user has the the child nodes in the grid expanded (it's an hierachical datagrid) they are collapsed when the line above is called. I have tried the Infragistics-centric myGrid.Rows.Refresh(RefreshRow.ReloadData) in place of "datasource = myDS" when a refresh is being performed. This indeed keeps the grid expanded to that node but does not update my grid with the new rows that have been added to the underlying datasource. Any wisdom in this area would be most appreciated.
 
You could save the state of each row, run the update and then reload each row's state, i don't have exact code but i did something similar with a treeview, maybe it'll help.

I checked each node was expanded and/or selected and stored the info in a hashtable. Note that you need to uniquely identify each row in the hashtable.

Silo4.


Code:
Public HTExpanded As Hashtable
Public HTSelected As Hashtable

'sub to refresh
SaveTreeState(OptionsTree)
    'Do your update here
GetTreeState(OptionsTree)

    Private Sub SaveTreeState(ByVal aTreeView As TreeView)
        If Not IsNothing(HTExpanded) Then
            HTExpanded.Clear()
            HTSelected.Clear()
        End If
        Dim n As cNode
        For Each n In aTreeView.Nodes
            SaveRecursive(n)
        Next
    End Sub
    Private Sub SaveRecursive(ByVal n As cNode)
        If n.IsExpanded Then
            HTExpanded.Add(n.FullPath & n.UID, "1")
        Else
            HTExpanded.Add(n.FullPath & n.UID, "0")
        End If
        If n.IsSelected Then
            HTSelected.Add(n.FullPath & n.UID, "1")
        Else
            HTSelected.Add(n.FullPath & n.UID, "0")
        End If
        Dim aNode As cNode
        For Each aNode In n.Nodes
            SaveRecursive(aNode)
        Next
    End Sub

    Private Sub GetTreeState(ByVal aTreeView As TreeView)
        Dim n As cNode
        For Each n In aTreeView.Nodes
            GetRecursive(n)
        Next
    End Sub
    Private Sub GetRecursive(ByVal n As cNode)
        If Not IsNothing(HTExpanded) Then
            If HTExpanded.Item(n.FullPath & n.UID) = "1" Then
                n.Expand()
            End If
            If HTSelected.Item(n.FullPath & n.UID) = "1" Then
                OptionsTree.SelectedNode = n
            End If
        End If

        Dim aNode As cNode
        For Each aNode In n.Nodes
            GetRecursive(aNode)
        Next
    End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top