Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Data.Datarow Sort

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

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 …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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

722 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