![]() |
OnClick Ereignis für StringGrid Zelle in FixedRow
Die erste Zeile meines StringGrids ist FIXED, ich kann also praktisch keine Zelle auswählen. Nun möchte ich aber eine Sortierfunktion einbauen, die das gesamte Grid sortiert je nachdem auf welche Zelle ich in der ersten Zeile geklickt habe
ID | Name | Datum Klicke ich auf Name wird nach Name sortiert, klicke ich auf Datum wird nach Datum sortiert, nur leider weiss ich nicht, wie ich abfragen soll, ob jemand drauf geklickt hat Ich habe übrigens aus optischen Gründen RowSelect = True gesetzt, heisst das, dass man nun eh nur noch abfragen könnte ob eine Zeile angeklickt wurde? |
Moin FlatG,
Du könntest versuchen das OnClick auf Fixed Rows / Colums im OnMouseUp zu simulieren, indem Du dort prüfst, ob die linke Maustaste diejenige war, die das Ereignis ausglöst hast, dann die "angeklickte" Zelle mit TStringGrid.MouseToCell ermittelst, und dann prüfst, ob es Zeile 0 war, und welche Spalte betroffen ist. |
Delphi-Quellcode:
und zum aufrufen der prozedur benutzt du:
procedure SortStringGrid(var GenStrGrid: TStringGrid; ThatCol: Integer);
const // Define the Separator TheSeparator = '@'; var CountItem, I, J, K, ThePosition: integer; MyList: TStringList; MyString, TempString: string; begin // Give the number of rows in the StringGrid CountItem := GenStrGrid.RowCount; //Create the List MyList := TStringList.Create; MyList.Sorted := False; try begin for I := 1 to (CountItem - 1) do MyList.Add(GenStrGrid.Rows[I].Strings[ThatCol] + TheSeparator + GenStrGrid.Rows[I].Text); //Sort the List Mylist.Sort; for K := 1 to Mylist.Count do begin //Take the String of the line (K – 1) MyString := MyList.Strings[(K - 1)]; //Find the position of the Separator in the String ThePosition := Pos(TheSeparator, MyString); TempString := ''; {Eliminate the Text of the column on which we have sorted the StringGrid} TempString := Copy(MyString, (ThePosition + 1), Length(MyString)); MyList.Strings[(K - 1)] := ''; MyList.Strings[(K - 1)] := TempString; end; // Refill the StringGrid for J := 1 to (CountItem - 1) do GenStrGrid.Rows[J].Text := MyList.Strings[(J - 1)]; end; finally //Free the List MyList.Free; end; end;
Delphi-Quellcode:
das funktioniert (getestet)
procedure TFormHaupt.Vorname1Click(Sender: TObject);
begin SortStringGrid(StringGrid1, 0); // 0 steht für die Spalte, die sortiert werden soll end; Grüße, dopeline :dancer: |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:12 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz