954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Custom row sorting in a DataGridView

Hello all,
I have a DataGridView that is being populated via SQL with one table and is being filtered by Stock Code. I need to sort the view of one Stock Code by Nutrient names, but the sequence number is in anther SQL table. it would be easy if i could put the sequence in one table but that's not possible, and there are 47 nutrients that need to be sorted in the View. eg, Calories, Fat, Saturated, Trans, cholesterol...

thank you
kyle :)

ginnipig
Newbie Poster
4 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

Why is it not possible to put the sequence in the same query you are populating your DataGridView?

Please show us these 2 queries.

adam_k
Practically a Posting Shark
803 posts since Jun 2011
Reputation Points: 256
Solved Threads: 149
 

I figured it out :), i wasn't aware that you could use one SQL select statement for multiple tables.

Private Sub BindDataNutr()
        Dim conn As OleDbConnection
        Dim SqlStr As String
        Dim dsNutr As New DataSet
        Dim daNutr As New OleDbDataAdapter
        conn = New OleDbConnection(SysproSqlString())
        conn.Open()
        SqlStr = "SELECT SBSI_NutritionalInfo.StockCode, SBSI_NutritionalInfo.Nutrient, SBSI_NutritionalInfo.Per100g, SBSI_NutritionalValues.NutrientUom, SBSI_NutritionalInfo.DataSource, SBSI_NutritionalValues.LabelSeq FROM  SBSI_NutritionalInfo INNER JOIN SBSI_NutritionalValues ON SBSI_NutritionalInfo.Nutrient = SBSI_NutritionalValues.Nutrient where StockCode = '" & Trim(Tbx_StkCode.Text) & "' ORDER BY SBSI_NutritionalValues.LabelSeq"
        'SqlStr = "select * From dbo.SBSI_NutritionalInfo where StockCode = '" & Trim(Tbx_StkCode.Text) & "'"
        daNutr = New OleDbDataAdapter(SqlStr, conn)
        daNutr.Fill(dsNutr)
        DGV_NutrUp.DataSource = dsNutr.Tables(0)
        DGV_NutrUp.Columns("LabelSeq").Visible = False
        DGV_NutrUp.Columns("StockCode").Visible = False
    End Sub
ginnipig
Newbie Poster
4 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: