Solved

Data.Datarow Sort

Posted on 2010-09-15
2
614 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 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now