Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Data.Datarow Sort

Posted on 2010-09-15
2
Medium Priority
?
689 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
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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

971 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