Mega Code Archive

 
Categories / Delphi / ADO Database
 

Sort DBGrid columns in 2 lines of code

Title: Sort DBGrid columns in 2 lines of code Question: Have you seen long examples of sorting DBGrids Online. Well here is an example in 2 lines of code. This will sort any column you want by double clicking on any cell in the column. Answer: procedure TForm1.DBGrid1DblClick(Sender: TObject); var str1: String; begin str1 := DBGrid1.SelectedField.FieldName; myadoqry.Sort := str1+' ASC'; end; You should allow the user to select a cell in a column. You can use the DBGrid's readonly property to disallow the user the ability to delete a row. just set DBGrid1.readonly := True; You can also do this from the Designer