Mega Code Archive

 
Categories / Delphi / VCL
 

Clear a selection in StringGrid

Title: Clear a selection in StringGrid Question: How to clear a highlighted cell in a grid Answer: If you want to get rid of the highlighted cell in a TStringGrid which does not have the focus or is used only to display data, try the following small procedure. procedure TForm1.GridClean(Sender: TObject); var hGridRect: TGridRect; begin hGridRect.Top := -1; hGridRect.Left := -1; hGridRect.Right := -1; hGridRect.Bottom := -1; (Sender as TStringgrid).Selection := hGridRect; end; Use it for example in the grid's OnExit event: var MyGrid: TStringGrid; ... GridClean(MyGrid);