Solved

Data.Datarow Sort

Posted on 2010-09-15
2
664 Views
Last Modified: 2013-12-25
I am a VB 6.0 programmer just getting my feet wet in a .NET app that I inherited, so have alot of questions that you will probably seeing this next week!

There is a form that has a ComboBox, and I found the code that is loading the DropDown, but I need the items sorted by another Field named "SortValue"

Here is the code the other person had in there.  I tried to put a ORDER BY behind the line that sets the foundRows = .

That didn't work, and not sure where to place it:

    Sub PopulateDropDown(ByVal parmTypeCodeGroupName As String, ByVal parmControl As ComboBox)
        Dim foundRows() As Data.DataRow
        Dim typeCodeItem As DataRow
        Dim i As Integer
        Try
            parmControl.Text = ""
            'foundRows = _7thwaveDataSet.Tables("TypeCodeGroupName").Select("TypeCodeGroupName Like '" + parmTypeCodeGroupName + "'")
            foundRows = _7thwaveDataSet.Tables("TypeCodeGroupName").Select("TypeCodeGroupName Like '" + parmTypeCodeGroupName + "'") 'group id = 25
            For i = 0 To foundRows.Length - 1
                typeCodeItem = foundRows(i)
                parmControl.Items.Add(typeCodeItem.Item("TypeCodeName").ToString)
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
            Me.Close()
        End Try
    End Sub
0
Comment
Question by:sharpapproach
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Expert Comment

by:Jambyte
ID: 33684967
you might want to use a dataview which has a sort property. check out an example here: http://msdn.microsoft.com/en-us/library/system.data.dataview.sort%28v=VS.71%29.aspx
0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 33686569
This another way sorting!!!
Dim dr As DataRow = dtTable.NewRow
        Dim comp As New System.Collections.Comparer(System.Globalization.CultureInfo.CurrentCulture)
        Dim intSortField As Int32 = dtTable.Columns.IndexOf("FieldToBeSorted")

        For cntOutter As Int32 = 0 To dtTable.Rows.Count - 1
            For cntInner As Int32 = 0 To dtTable.Rows.Count - 2
                If comp.Compare(dtTable.Rows(cntInner).Item(intSortField), dtTable.Rows(cntInner + 1).Item(intSortField)) = 1 Then
                    dr.BeginEdit()
                    dr.ItemArray = dtTable.Rows(cntInner + 1).ItemArray
                    dr.EndEdit()
                    dtTable.Rows.RemoveAt(cntInner + 1)
                    dtTable.Rows.InsertAt(dr, cntInner)
                    dr = dtTable.NewRow
                End If
            Next cntInner
        Next cntOutter 

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Web page design problem 3 41
Shared Service Environment 2 54
GET INFO ABOUT WHAT THE PRINTER IS DOING ? 11 76
CSS styling problem 3 28
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question