Autor Beitrag
MH1987
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 98



BeitragVerfasst: Do 13.07.06 07:27 
hi,

kann mir jemand sagen wie ich eine bestimmte zelle in einem stringgrid per button klick fokusieren kann??

danke

gruß
matthias


Moderiert von user profile iconraziel: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Sa 05.08.2006 um 09:05
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Do 13.07.06 07:55 
morgen ;)

mit
ausblenden Delphi-Quelltext
1:
2:
stringgrid.row := 5;
stringgrid.col := 3;


solltest du zum beispiel die Zelle [3,5] auswählen können
MH1987 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 98



BeitragVerfasst: Do 13.07.06 22:03 
danke hat soweit funktioniert.
nur wenn ich das ganze jetzt für ein stringgrid benutze, das sich selbst seine reihenhöhe anpasst, also so, dass auch langer text untereinander geschrieben wird, funktioniert das ganze nicht mehr so richtig.
der cursor springt zwar auf die entsprechende zelle, aber fokussiert wird weit darüber....

woran kann das liegen, und wie kann ich das beheben?


hier der quelltext:

ausblenden volle Höhe Delphi-Quelltext
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:
[...]

procedure TFormFilme.fokusiere(Buchstabe: Char);
var i: integer;
    gefunden: boolean;
begin
  i:= 0;
  gefunden:= false;

  while (i < self.SgDatenAusgabe.RowCount) and not gefunden do
    if (uppercase(self.SgDatenAusgabe.Cells[1,i])[1] = Buchstabe)
      then
        begin
          self.SgDatenAusgabe.Row:= i;
          gefunden:= true;
        end
      else
        inc(i);
end;

[...]

procedure GrowRect(var Rect: TRect; const pixel: Integer);
begin
  Dec(Rect.Left, pixel);
  Inc(Rect.Right, pixel);
  Dec(Rect.Top, pixel);
  Inc(Rect.Bottom, pixel);
end;

procedure TFormFilme.UpdateRowHeight(sg: TStringGrid; const iRow, iHeight: Integer);
begin
  with SgDatenAusgabe do
  if iHeight > RowHeights[iRow] then
    RowHeights[iRow] := iHeight;
end;

procedure TFormFilme.SgDatenAusgabeDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  s: String;
begin
  with Sender as TStringGrid do
  begin
    s := Cells[ACol, ARow];
    Canvas.FillRect(Rect);
    if ACol = 0
      then Canvas.Font.Color:= clblue;
    GrowRect(Rect, -2);
    UpdateRowHeight(
      Sender as TStringGrid, ARow,
      DrawText(Canvas.Handle, PChar(s), Length(s), Rect, DT_WORDBREAK) + 4);
  end;
end;

[...]

procedure TFormFilme.Button4Click(Sender: TObject);
begin
  Fokusiere('D');
end;

end.


das stringgrid hat 4 spalten:

Ändern-------FilmName-------FilmNummer-------FilmBeschreibung


und ich möchte ein weiteres stringgrid o.Ä. einbauen, welches alle buchstaben des alphabets beinhaltet, und wenn man auf einen buchstaben klickt, wird man zum entsprechenden eintrag der Filmnamen geschickt.
eben eine suchhilfe nach anfangsbuchstaben
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Fr 04.08.06 22:16 
Hallo,

was meinst Du mit fokussiert wird weit darüber? > Eine Zelle wird selectiert(blauer Hintergrund o.ä.) und eine Zelle an anderer Stelle erhält einen Focusrahmen; meinst Du das?
Häng doch mal einen Screenshoot an um das Problem besser nachvollziehen zu können.

Deinen Code hab ich in eine neue Anwendung kopiert, klappt astrein.

Veranstaltest Du an den Stellen mit [...] im Code noch etwas anderes mit dem StringGrid?

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )