Question try to sort datagridview

didgydont

Active member
Joined
Mar 2, 2009
Messages
37
Programming Experience
Beginner
hi all i have added 3 colums to a data grid view then i add the data manualy
VB.NET:
While Not Rec.EOF

            sfbarcode = Rec.Fields("barcode").Value
            sfprice = FormatCurrency(Rec.Fields("price").Value)
            sfitem = Rec.Fields("Item").Value
            DataGridView1.Rows.Add(sfbarcode, sfitem, sfprice)
end while

the problem is it sorts price as 1,11,2 instead of 1,2,11
i have looked around on google cant seem to find anything that work on vb 2008 express
thank you for your time
 
Strings sort like that, not numeric values. Add the data items as numeric values instead of strings to sort the problem. Since FormatCurrency works for you it must mean that the price value was numeric before you converted to a string, so don't do that, you can configure the dgv column to display numeric data in currency format. If your sf variables are declared as data type String, then you are implicitly and unaware converting the data to string here also, don't do that either.
 
thank you didnt understand everything you said as i started playin with vb about 2 weeks ago, but got it working it was becuase i dim vaule, and the format as currency did formating in data grid view and works great
 
Back
Top