Тема: DBGrid и Hint
Показать сообщение отдельно
  #2  
Старый 08.09.2011, 08:45
Аватар для Shoni
Shoni Shoni вне форума
Прохожий
 
Регистрация: 02.09.2011
Адрес: Кострома
Сообщения: 45
Версия Delphi: 7
Репутация: 165
По умолчанию

Нашла ещё такой вариант:
Код:
type
   TMouseGrid = class(TCustomDrawGrid);
   THackDBGrid = Class(TDBGrid);

По движению мыши:
var s: string;
    DLink : TDataLink;
    nCol,nRow:Integer;
    OldPosRecord: Integer;// vecchia posizione del cursore
  Procedure NoHint;
  begin  // nel caso di nessun hint .. lo nascondo
    DBGrid1.Hint:='';
    Application.HideHint;
  end;
begin
  nCol := -1;
  nRow := -1;
  s:= '';
  if DBGrid1.DataSource.DataSet.Active then  // solo se il dataset и aperto
  begin
    TMouseGrid(Sender).MouseToCell(X, Y, nCol, nRow);  //Mi ritorna riga colonna del mouse
    if (nCol>0) and (nRow>0) then
    begin
      DLink:=THackDBGrid(DBGrid1).DataLink;  //mi becco il datalink
      if Assigned(DLink) then  // и sicuramente assegnato .. ma .. 
      begin
        OldPosRecord := DLink.ActiveRecord;  // salvo il cursore del record
        DLink.ActiveRecord := nRow - 1;  //-1 conto che ci sia l'intestazione
        if assigned(DBGrid1.DataSource.DataSet.Fields[nCol - 1]) then
          s := DBGrid1.DataSource.DataSet.Fields[nCol - 1].AsString; // prendo il valore
        DBGrid1.Hint := s;   // assegno il valore all'hint della grid
        Application.ActivateHint(DBGrid1.ClientToScreen( Point(X,Y) ));  //mostro l'hint nella posizione del cursore
        DLink.ActiveRecord := OldPosRecord; // ripristino posizione
      end
      else
        NoHint;
    end
    else
      NoHint;
  end
  else
   NoHint;
Админ: Пользуемся тегами для оформления кода!

Правда, почему-то не работает
__________________
Memento Mori(арти)
Ответить с цитированием