Arsip: Seleksi baris DBGrid menggunakan event OnMouseMove


by adludin in Articles more 19 years ago 2632
Tip dan trik ini berguna untuk menyeleksi record/baris pada DBGrid berdasarkan gerakan mouse yang melintas pada DBGrid...
Tambahkan kode berikut pada deklarasi type : #F8F8F8>
typeTHackDBGrid = class(TDBGrid);
...
...
Kode dibawah ditambahkan pada event OnMouseMove dari DBGrid : #F8F8F8>
procedureTForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var gc: TGridCoord;
begin
  gc:= DBGrid1.MouseCoord(x, y);
  if (gc.X > 0) AND (gc.Y > 0) then
  begin
    DBGrid1.Cursor:=crHandPoint;
    DBGrid1.DataSource.DataSet.MoveBy
        (gc.Y - THackDBGrid(DBGrid1).Row);
  end
  else DBGrid1.Cursor:=crDefault;
end;
Untuk menambahkan efek highlight, tambahkan kode berikut pada event OnDrawColumnCell dari DBGrid : #F8F8F8>
 if (THackDBGrid(DBGrid1).DataLink.ActiveRecord + 1 =
      THackDBGrid(DBGrid1).Row)
  or (gdFocused in State) or (gdSelected in State) then
  begin
    DBGrid1.Canvas.Brush.Color := clBlueSky;
    DBGrid1.Canvas.Font.Style := DBGrid1.Canvas.Font.Style + [fsBold];
    DBGrid1.Canvas.Font.Color := clRed;
  end;
Catatan : Pilih Option RowSelect DBGrid agar True.. Semoga bermanfaat...

Coinfest

Pascal Indonesia is Coinfest Asia 2024's official community partner! 🀝
β˜€οΈ Take part in Asia’s immersive Web3 festival, where innovation meets adoption.
🎟 Get your tickets at www.coinfest.asia and use our special promo code : CA24PASCALINDO to get 10% off!

Why Coinfest Asia?
● Unconventionally Engaging
Our immersive setting and programming leave you with more memory markers than any other event
● Dive into Emerging Markets
Get connected in Southeast Asia; the fastest-growing Web3 region in the world
● Jump straight into Adoption
Foster collaborations directly in Indonesia where there are 437k new crypto users each month

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com