Wie kann man verhindern das bei einer Virtuelle Listbox (siehe Code), beim betätigen der Taste Enter, wenn die Markierung nicht die erste Zeile ist, immer die erste Zeile automatisch markiert wird.
Eine indirekte Lösung mit Application.OnIdle setze ich z. Z. ein finde aber das diese Lösung unsauber ist, wäre deswegen dankbar für eine bessere.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls;
type TForm1 = class(TForm) ListBox1: TListBox; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure FormShow(Sender: TObject); private ListBox: TListBox; F_ListBoxUrl0OldItemIndex : integer; procedure ListBoxData(Control: TWinControl; Index: Integer;var Data: String); procedure ListBoxKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState); procedure AppOnIdle(Sender: TObject; var Done: boolean); public end;
var Form1: TForm1;
implementation {$R *.dfm} const C_MyDaten : array[0..3] of string =('Date1','Date2','Date3','Date4'); procedure TForm1.FormCreate(Sender: TObject); begin ListBox := TListBox.Create(self); with ListBox do begin Parent := self; Top := 10; Left := 10; Width := 200; Height := 200; Style := lbVirtual; OnData := ListBoxData; OnKeyDown := ListBoxKeyDown; Count := high(C_MyDaten)+1; ItemIndex := 2; end; end; procedure TForm1.FormShow(Sender: TObject); begin ListBox.SetFocus; end; procedure TForm1.FormDestroy(Sender: TObject); begin ListBox.Free; end; procedure TForm1.ListBoxData(Control: TWinControl; Index: Integer;var Data: String); begin Data := string(C_MyDaten[Index]); end; procedure TForm1.ListBoxKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState); begin if Key = VK_RETURN then F_ListBoxUrl0OldItemIndex := TListBox(Sender).ItemIndex; end; procedure TForm1.AppOnIdle(Sender: TObject; var Done: boolean); begin Done := true; if F_ListBoxUrl0OldItemIndex > 0 then ListBox.ItemIndex := F_ListBoxUrl0OldItemIndex; F_ListBoxUrl0OldItemIndex:=0; end; end. |
MFG
Moderiert von
raziel: Code- durch Delphi-Tags ersetzt