Monday 15 July 2013

Delphi -drawgrid shows multiple instance of painted cells when any arrow key is pressed. how to correct it -


When I press the button, the selected cells are featured in Delphi Drogrid. But when I press an arrow key that appears several times to the painted cells.

Enter image details here

Shows 3 blocks

  

 < Code> Unit booking 2; Interface access to Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Gridges, Vcl.StdCtrls , Data DB, data V. DADADB; Type CellInfo = record BkColor: TColor; End; TScheduleItem = record text: string; Line: Integer; FirstX: integer; LastX: integer; Res_ID, Room_No: string; End; TArr_Rows = record line_no: integer; Room_no: string; End; TArr_Col = record col_no: integer; B_det: TDT; End; Tbookings2_frm = Class (TForm) Panel 1: TPanel; Panel 2: Teppenal; BGrid: Tidgrad; Button 1: Tibbon; QRooms: TADOQuery; QRoomsRoom_No: TStringField; QRoomsRoomType: TStringField; QRoomsDescription: TStringField; QRoomsdefault_price: TBCdfiled; QRoomsmax_pax: TIntegerField; QRoomsroom_status: TStringField; Process bGridDrawCell (Sender: TubEygect; Ecol, ARO: Integer; Rect: TRCT; State: TGIRDDradeState); Functionality create_env (start_date: tDate); Click Process Button 1 (Sender: Tubect); Private {Private Announcements} Room: The array of CellInfo; Public {public declaration} tot_rooms: integer; Rooms: array of strings; Shedule_item: array of TScheduleItem; Arr_rows: array of TArr_Rows; Col_count: integer; Days_h, sun_mon, mon: array [0..50] of string; Short_days: String array [1.7]; ShortMonthNames: Array of String [1..12]; End; Var booking 2_frame: tabbook 2_frame; Implementation {$ R *. Dfm} uses data, data_guest; Process Tbookings2_frm.bGridDrawCell (sender: tobjject; ax, aro: integer; rect: tract; state: tegirddurstate); Var cellindex: integer; Start the cellindex: = (Arrow * BGrid Roukount) + Acol; If gdFixed in the state then start bgrid.Canvas.Brush.Color: = bGrid.FixedColor; End and if (state * [gds connected, gdhottrack]) and lt; & Gt; [] Then start bGrid Canvas Brush. Color: = clHighlight; End and start bGrid.Canvas.Brush.Color: = Room [cellindex] .bkColor; End; BGrid.Canvas.FillRect (Rect); If the GDFcoxed BGRD in the state Canvas DraftCorrect (Rack); End; Process Tbookings2_frm.Button1Click (Sender: Tubect); Var R: Tegirdart; Line, col: integer; Starting {R Left: = 6; R.Top::3; R.Right: = 8; R.Bottom: = 3; } R: = bgrid.selection; //bGrid.Selection :=R; For Roe: = R. To r Start for the Colonel: = R. R for R. Start the cell [[line * bGrid.RowCount + Col]]. BkColor: = clAqua; End; End; End; Process Tbookings2_frm.create_env (start_date: tDate); Var room_count, line_ count: integer; I, Acole, Fixed with: integer; Stdate, endDate: tDate; Year, month, day, s_day: word, s, str1, str_stDate, str_endDate: string; Start // Check how many rooms qRooms.Close; QRooms.SQL.Clear; QRooms.SQL.Add (choose 'from pm_Rooms * where room_status =' 'AVAIL' '); QRooms.Open; Tot_rooms: = qrooms.RecordCount; Setlanda (room, totals + 4); Setline (schedule_it, 50); Settlei (RR_RO, Tita_room + 3); StDate: = start_date-10; ENDDATE: = stDate + 50; Room_count: = qrooms.RecordCount; Bgrid.RowCount: = room_count + 3; Start with 3 bits for 3 fixed rows with bgrid: = 1 ColCount - 1 start bgrid. Colewids [i]: = 30; //bgrid.Canvas End; End; Bgrid.colwidths [0]: = 100; // ------------------------- Setlanda (cell, bgid. Roucount * bGrid.ColCount); For I: start high (cell) cells from high (cells) [I]. BkColor: = bGrid.Color; End; End; End.    

index count of your cell array (line * bGrid.RowCount) + kernel is incorrect (line * bGrid.ColCount) + kernel because the ColCount elements are per line.

No comments:

Post a Comment