﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » Setting Order By in Browse Dialog Search Results</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Thu, 09 Apr 2026 12:42:12 GMT</lastBuildDate><ttl>20</ttl><item><title>Setting Order By in Browse Dialog Search Results</title><link>http://forum.strataframe.net/FindPost32928.aspx</link><description>Hello all,&amp;nbsp;&lt;br/&gt;&lt;br/&gt;&lt;div&gt;I have a browse dialog that is querying on a table with 10s of thousands of records.&amp;nbsp;&lt;div&gt;When the user searches, with criteria selected, there are a lot of results. But, I have the Browse Dialog set to only get TOP 1000, to improve responsiveness.&lt;br/&gt;&lt;br/&gt;&lt;div&gt;My intention is to have the search results return the latest records first, sorted by the added_date field. So query I would need the Browse Dialog to perform is something like this: SELECT TOP 1000 * ... ORDER BY added_date DESC&lt;br/&gt;&lt;br/&gt;&lt;div&gt;When I set the sort order in the SearchFields editor, it sorts the records that it gets back from a regular query with no Order By clause, so the user is not getting the latest records. They're getting the TOP 1000 records in the order that they are in the table.&amp;nbsp;&lt;br/&gt;&lt;br/&gt;&lt;div&gt;When I set the BrowseDialog.OrderBy property, I can put the field there, but I can't specify "DESC"; I get the SQL error, "Invalid column name 'added_date DESC'."&lt;br/&gt;&lt;br/&gt;&lt;div&gt;Could someone please help me display the latest records in the Browse Dialog.&lt;br/&gt;&lt;br/&gt;&lt;div&gt;Thank You,&lt;div&gt;Govinda</description><pubDate>Mon, 13 Apr 2015 15:30:49 GMT</pubDate><dc:creator>Govinda Berrio</dc:creator></item><item><title>RE: Setting Order By in Browse Dialog Search Results</title><link>http://forum.strataframe.net/FindPost32933.aspx</link><description>Hi Govinda&lt;br/&gt;Awesome and simple!!!&lt;br/&gt;&lt;br/&gt;Thanks for sharing this idea!!!</description><pubDate>Mon, 13 Apr 2015 15:30:49 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Setting Order By in Browse Dialog Search Results</title><link>http://forum.strataframe.net/FindPost32932.aspx</link><description>That is a good strategy, Edhy, but I can't spend the time converting it over.&amp;nbsp;&lt;div&gt;I did go ahead with the idea that I had and it worked. See the code below.&lt;br/&gt;&lt;br/&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;[codesnippet]&lt;/span&gt;&lt;/span&gt;private void JobTicketBD_BeforeSearchExecuted(object sender, BrowseDialogBeforeSearchExecutedEventArgs e)&lt;div&gt;{&lt;div&gt;&amp;nbsp; &amp;nbsp; e.QueryInfo.OrderByFields.Add("add_date_descending");&lt;div&gt;&amp;nbsp; &amp;nbsp; e.QueryInfo.Tokens.Add("add_date_descending", "add_date DESC");&lt;div&gt;}&lt;span&gt;&lt;span&gt;[/codesnippet]&lt;/span&gt;&lt;br/&gt;&lt;/span&gt;</description><pubDate>Mon, 13 Apr 2015 15:09:04 GMT</pubDate><dc:creator>Govinda Berrio</dc:creator></item><item><title>RE: Setting Order By in Browse Dialog Search Results</title><link>http://forum.strataframe.net/FindPost32931.aspx</link><description>Hi Govinda,&lt;br/&gt;&lt;br/&gt;You are welcome.&lt;br/&gt;&lt;br/&gt;I spend sometime with the BD and was able to duplicate your easy right away and yes you are right about the &lt;span id="ctl00_ctlContentPlaceHolder_ctl00_ctlTopic_ctlPanelBar_ctlTopicsRepeater_ctl01_lblFullMessage"&gt;OrderByFields property.&amp;nbsp; I know you can use the BD with a Stored Procedure and a view, but probably if your don't have too many search fields, you can simply build your own search feature.&lt;br/&gt;&lt;br/&gt;Here is what I do today....&lt;br/&gt;&lt;/span&gt;&lt;ul&gt;&lt;li&gt;&lt;span id="ctl00_ctlContentPlaceHolder_ctl00_ctlTopic_ctlPanelBar_ctlTopicsRepeater_ctl01_lblFullMessage"&gt;I use DevExpress controls, specially their grid, it is very powerful, flexible and super fast.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span id="ctl00_ctlContentPlaceHolder_ctl00_ctlTopic_ctlPanelBar_ctlTopicsRepeater_ctl01_lblFullMessage"&gt;In most cases I will always show the grid with many records so end user select the one they need.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span id="ctl00_ctlContentPlaceHolder_ctl00_ctlTopic_ctlPanelBar_ctlTopicsRepeater_ctl01_lblFullMessage"&gt;I create a View to be used with the grid and then a Stored Procedure (SP) to grab the data for the view.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span id="ctl00_ctlContentPlaceHolder_ctl00_ctlTopic_ctlPanelBar_ctlTopicsRepeater_ctl01_lblFullMessage"&gt;Once your SP is working as expected then create your search fields controls and then call your SP to load the grid.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;I know this is not a generic method as with the BD, but I have full control of the search, specially optimizing it and showing the data the way I want with the DevExpress grid.&amp;nbsp; See the attached image to see how it looks and if you need more details, just let me know.</description><pubDate>Sun, 12 Apr 2015 16:50:29 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Setting Order By in Browse Dialog Search Results</title><link>http://forum.strataframe.net/FindPost32930.aspx</link><description>Hi Edhy,&amp;nbsp;&lt;br/&gt;&lt;br/&gt;&lt;div&gt;Thanks for the reply.&amp;nbsp;&lt;div&gt;I'm looking in the framework code that builds the sql from the QueryInfo object, and it does not provide facilities for specifying a sort direction.&amp;nbsp;&lt;div&gt;OrderByFields is simply a StringCollection and the framework code assumes each item in the list is a field name.&amp;nbsp;&lt;br/&gt;&lt;br/&gt;&lt;div&gt;While I was in the code, I noticed how the ReplaceTokens logic works and I think I'm going to use the OrderByFields and Tokens collections in conjunction to do what I need.&amp;nbsp;&lt;br/&gt;&lt;br/&gt;&lt;div&gt;I'll let you know if I can get it working.&lt;br/&gt;&lt;br/&gt;&lt;div&gt;Govinda</description><pubDate>Sun, 12 Apr 2015 14:03:29 GMT</pubDate><dc:creator>Govinda Berrio</dc:creator></item><item><title>RE: Setting Order By in Browse Dialog Search Results</title><link>http://forum.strataframe.net/FindPost32929.aspx</link><description>Hi Govinda,&lt;br/&gt;Sorry but I have not used the BD in a long time.&amp;nbsp; I normally create my own search fields and use a MS-SQL stored procedure to grab the data in the way I want.&lt;br/&gt;&lt;br/&gt;The good thing is that the BD exposes some events that will allow you to manipulate the QueryInfo object and I am pretty sure you can trap any of these events and insert the required ORDER BY clause.&lt;br/&gt;&lt;br/&gt;Take a look at the SF help file in the following spot: Application Framework-&amp;gt;UI Layer-&amp;gt;Controls-&amp;gt;Browse Dialog-&amp;gt;Events&lt;br/&gt;&lt;br/&gt;Also take a look at this link &lt;a href="http://forum.strataframe.net/Search.aspx?Keywords=BeforeSearchExecuted"&gt;&lt;a href="http://forum.strataframe.net/Search.aspx?Keywords=BeforeSearchExecuted"&gt;http://forum.strataframe.net/Search.aspx?Keywords=BeforeSearchExecuted&lt;/a&gt;&lt;/a&gt; from the forums which has related information about the BD.&lt;br/&gt;&lt;br/&gt;Please let us know how you fix this issue.&lt;br/&gt;&lt;br/&gt;P.S.&lt;br/&gt;I took a quick look in the SF help field at the QueryInformation Members and there is a property named OrderByFields, use the debugger to break in the BeforeSearchExecuted event and look at the OrderByFields property to examine its value and probably all you need to do is replace it with your own values.&lt;br/&gt;Good luck!!!</description><pubDate>Fri, 10 Apr 2015 19:54:41 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item></channel></rss>