Solved

Data.Datarow Sort

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
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…

825 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