Как зафиксировать столбцы в DBGrid
Как зафиксировать столбцы в DBGrid
Как зафиксировать столбцы в DBGrid Это маленькая вставка в Ваш наследник от tcustomdbgrid, которая решает данную задачу. === begin dbgridex.pas === // ---------------------------------------------------------------------------- - destructor tdbgridex.destroy; begin _hidecolumnsvalues.free; _hidecolumns.free; inherited destroy; end; // ---------------------------------------------------------------------------- constructor tdbgridex.create(component : tcomponent); begin inherited create(component); ffreezecols := ?; _hidecolumnsvalues := tlist.create; _hidecolumns := tlist.create; end; // ---------------------------------------------------------------------------- procedure tdbgridex.keydown(var key: word; shift: tshiftstate); begin if (key = vk_left) then colbeforeenter(-1); if (key = vk_right) then colbeforeenter(1); inherited; end; // ---------------------------------------------------------------------------- procedure tdbgridex.setfreezecolor(acolor : tcolor); begin invalidaterow(0); end; // ---------------------------------------------------------------------------- procedure tdbgridex.setfreezecols(afreezecols : integer); begin ffreezecols := afreezecols; invalidaterow(0); end; // ---------------------------------------------------------------------------- procedure tdbgridex.colenter; begin colbeforeenter(0); if assigned(oncolenter) then oncolenter(self); end; // ---------------------------------------------------------------------------- procedure tdbgridex.colbeforeenter(adelta : integer); var nindex : integer; function readwidth : integer; var i : integer; begin i := _hidecolumns.indexof(columns[nindex]); if i = -1 then result := 120 else result := integer(_hidecolumnsvalues[i]); end; procedure savewidth; var i : integer; begin i := _hidecolumns.indexof(columns[nindex]); if i <> - 1 then begin _hidecolumnsvalues[i] := pointer(columns[nindex].width); end else begin _hidecolumns.add(columns[nindex]); _hidecolumnsvalues.add(pointer(columns[nindex].width)); end; begin for nindex := 0 to columns.count - 1 do begin if (columns[nindex].width = 0) then begin if (nindex + 1 <= freezecols) or (nindex >= selectedindex + adelta) then columns[nindex].width := readwidth; end else begin savewidth; if (nindex + 1 > freezecols) and (nindex < selectedindex + adelta) and (nindex + 1 < columns.count) and (freezecols > 0) then columns[nindex].width := 0; end; === end dbgridex.pas ===