troubleshooting Question

DataGridView control cannot be sorted if it is bound to an IBindingList that does not support sorting.

Avatar of Netlink2
Netlink2 asked on
Visual Basic Classic.NET ProgrammingVisual Basic.NET
7 Comments2 Solutions5184 ViewsLast Modified:
I want to sort on a column named "Phone" (not defined as a title in this code)

I've checked this site which I think should help with the problem but I'm unsure how to impliment it in my code. 

The code is:
Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
        'initialize connection...
        conn = clsTools.GetDBConn
        'set query string...
        Dim queryString As String, strLen As Integer
        'Can be used in MySQL
        queryString = "SELECT * FROM details WHERE STATE = WA"
        'initialize command object...
        If chkOrder.Checked = True Then
            'doesn't work due to error in mysql "sort order" due to bad management of hdd swap file or ram
            queryString = queryString & " ORDER BY Phone"
        End If
        Dim command As New MySqlCommand(queryString, conn)
        'use command object to fill data reader...
        Dim reader As MySqlDataReader = command.ExecuteReader()
        'Bind reader to datagrid...
        Dim source As New BindingSource
        source.DataSource = reader
        DGVsearch.DataSource = source
        If chkOrder.Checked = True Then


            DGVsearch.Sort(DGVsearch.Columns(1), System.ComponentModel.ListSortDirection.Ascending)
        End If
        MsgBox("Search Done")
    End Sub

Public Class clsTools

    Public Shared Function GetDBConn() As MySqlConnection
        Dim myConnection As MySqlConnection
        Dim sConnStr As String
        sConnStr = "server=" & Form1.cmbIP.Text & ";user id=remote;Password=remote;database=Lists;persist security info=True"
        myConnection = New MySqlConnection(sConnStr)
        Return myConnection
    End Function
End Class

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros