Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting data in a datagrid

Status
Not open for further replies.

moben

IS-IT--Management
Feb 5, 2002
116
0
0
GB
I have a datagrid in vb6 which is linked to a recordset query from Access2000. Data display ok, but is sorted incorrectly.

The query 'feeding' the grid is simple i.e. select * from xtable order by xnum.

Unfortunatley the data is orered incorrectly within the datagrid.

Is there a sort option/function for the datagrid ?
 
You can force its behavior by using it as an unbound control & populating with code. Here is a sample that I used in an app:
Code:
    With flxItem
        .Rows = rsDMI.RecordCount + 1
        For intRecordCounter = 1 To rsDMI.RecordCount
            strTotal = Format(CSng(rsDMI!AMOUNT) * 0.01, "$####0.00")
            strQuantity = Format(CSng(rsDMI!RPT_GEN_COPY_CNT) * 0.1, "##0.0")
            strPrice = Format(CSng(rsDMI!AMOUNT_2) * 0.01, "$####0.00")
            .Row = intRecordCounter
            .Col = 0
            .Text = rsDMI!product_name
            .Col = 1
            .Text = strPrice
            .Col = 2
            .Text = strQuantity
            .Col = 3
            .Text = strTotal
            .Col = 4
            .Text = rsDMI!ITEM_CD
            rsDMI.MoveNext
        Next intRecordCounter
    End With

This assumes a flexgrid control called flxItem and an open recordset called rsDMI.

The early bird may get the worm, but the second mouse gets the cheese in the trap.
 
I wouldn't do that, just to solve a problem whose source I didn't understand. I'd gain an understanding of the problem instead. Is there a sort going on in the code that the OP isn't aware of? Does the DataGrid have a Sort order set? Som other strange phenomenon? And so on.
 
Just old school programming - was taught to use unbound controls & code whenever possible to keep total control of the application. I agree that controls bound to the data control or data environment are easier to use.

The early bird may get the worm, but the second mouse gets the cheese in the trap.
 
Well, that's true too, but it may be that the problem isn't solved by that, and worse yet that it appears to be solved on the surface and isn't really.
 


>select * from xtable order by xnum


moben,
What type of field is "xnum", if this is not ordering the way you want? Is this field declared as numeric or text in the database table? If as text, then you will need to format the value in that column in the original "Select" statement, or change it to a real number field, or add a new field to do this formating with, if you are using a MSDataGrid.
 
moben, SB is pointing out the most likely cause of your difficulty. Different data types can have different sorting characteristics.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top