Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sorting DatabaseBrowser

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
dnarayan



Joined: 22 Oct 2007
Posts: 3

PostPosted: Mon Oct 22, 2007 1:25 pm    Post subject: Sorting DatabaseBrowser Reply with quote

I am by no means an expert programmer but I have been tasked with making a viewer for a database of sorts. The database is actually just a bunch of CSV files which I can open as a database using ADO. I have been able to populate the tree and define multiple levels and what not. However, I can not figure out how to make it sort correctly.

I think it has something to do with the TypedListName and TypeName properties in the databinding tab. In the DatabaseBrowser sample the different classes (Vehicle, Incident) are placed in the TypedListName whereas in mine I can only get the thing to work properly if I put them in TypeName. The structures of my classes are identical to the example (with different names) and they inherit VirtualRecord. Am I missing something?

Example class I am using:
Code:

Imports System
Imports Infralution.VirtualData

Public Class dbScript
    Inherits VirtualRecord

    Public ReadOnly Property ID() As Long
        Get
            Return CLng(GetValue("ID"))
        End Get
    End Property

    Public ReadOnly Property fType() As String
        Get
            Return IIf(CStr(GetValue("fType")) = "Date", "RunDate", CStr(GetValue("fType")))
        End Get
    End Property

    Public ReadOnly Property Name() As String
        Get
            Dim alpha As String
            alpha = GetValue("mName")
            If Double.TryParse(alpha, Nothing) Then
                If CLng(alpha) > 30000 Then
                    alpha = Format(Date.FromOADate(CDbl(alpha)), "d MMMM yyyy")
                End If
            End If
            Return CStr(alpha)
        End Get
    End Property

    Public ReadOnly Property Runs() As RunRecordset
        Get
            If _runs Is Nothing Then
                _runs = New RunRecordset(fType, GetValue("mName"))
            End If
            Return _runs
        End Get
    End Property

    Private _runs As RunRecordset

End Class

Public Class ScriptRecordset
    Inherits VirtualRecordset

    Dim fType As String

    Public Sub New(ByVal filterType As String)
        MyBase.New(GetType(dbScript), LogDatabase.Connection, "Runs", "ID", "SELECT DISTINCT " & IIf(filterType = "Date", "RunDate", filterType) & " AS mName, 1 AS ID, '" & filterType & "' AS fType FROM runs.csv runs LEFT JOIN structure.csv structure ON runs.ScriptID = structure.ID")
        Me.Refresh(True)

        fType = filterType
        Me.SortDirection = ComponentModel.ListSortDirection.Ascending
        If fType = "Date" Then
            Me.SortDirection = ComponentModel.ListSortDirection.Descending
        End If
    End Sub
    Protected Overrides Function GetSortClause() As String
        Select Case SortField
            Case Nothing
                Return IIf(fType = "Date", "RunDate", fType) & " {0}"
            Case Else
                Return MyBase.GetSortClause()
        End Select
    End Function


End Class
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Oct 22, 2007 10:43 pm    Post subject: Reply with quote

You are right - it is related to using the TypedListName. If you specify this it indicates to Virtual Tree that the datasource supports the ITypedList interface. Virtual Tree can then use the methods provided by this interface to implement sorting.

For a VirtualRecordset the TypedListName is the name of the table that the recordset is bound to. So in your case you would need to specify "Runs" as the TypedListName (I'm guessing that is the name of the table). In the sample project we use a convention of naming the strongly typed VirtualRecord the same as the table - so this distinction isn't so obvious.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
dnarayan



Joined: 22 Oct 2007
Posts: 3

PostPosted: Tue Oct 23, 2007 8:59 am    Post subject: Reply with quote

Thanks so much that fixed the problem.

Now I have another question: when I sort, it queries child records that have not been expanded yet for some reason. This also occurs in the databasebrowser sample. I have a very large database and these queries make sorting VERY slow. Is there some way to prevent the queries to the children if they are not expanded?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Oct 23, 2007 10:03 pm    Post subject: Reply with quote

The child record queries occur because Virtual Tree needs to determine whether each of the displayed rows has children (to determine whether the expansion indicator should be displayed). You can change this behaviour by setting the RowBinding.ChildPolicy to LoadOnExpand. This means that the expansion indicator is always displayed initially and the query is only performed if the user expands a row. A side effect of this is that if a row does not have any children then when the user expands the row the expansion indicator will disappear.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group