标签:do begin end ACol ARow ComboBox 单元格 StringGrid Sender
一、初始化控件状态
procedure TForm7.FormCreate(Sender: TObject); begin with StringGrid1 do begin ColWidths[0] := 15; Cells[1, 0] := 'Combobox'; ColWidths[1] := 100; Cells[2, 0] := 'DateTimePicker'; ColWidths[2] := 100; Cells[3, 0] := 'Form'; ColWidths[3] := 100; end; ComboBox1.visible := False; DateTimePicker1.Visible := False; end;
二、选择单元格显示控件
procedure TForm7.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); var R: TRect; org: TPoint; begin if Form8 = nil then Application.CreateForm(TForm8, Form8); with Sender as TStringGrid do begin //第一列 if ACol = 1 then begin Perform(WM_CANCELMODE, 0, 0); R := CellRect(ACol, ARow); org := Self.ScreenToClient(ClientToScreen(R.topleft)); with ComboBox1 do begin SetBounds(org.X, org.Y, R.right - R.left, Height); itemindex := Items.IndexOf(Cells[ACol, ARow]); Show; BringToFront; SetFocus; DroppedDown := True; end; end; if ACol = 2 then begin Perform(WM_CANCELMODE, 0, 0); R := CellRect(ACol, ARow); org := Self.ScreenToClient(ClientToScreen(R.topleft)); with DateTimePicker1 do begin SetBounds(org.X, org.Y, R.right - R.left, Height); if Cells[ACol, ARow] <> '' then Date := StrToDate(Cells[ACol, ARow]); Show; BringToFront; SetFocus; end; end; if ACol = 3 then begin Perform(WM_CANCELMODE, 0, 0); Form8.Caption := VarToStr(ARow) + '-' + VarToStr(ACol); Form8.ShowModal; with StringGrid1 do StringGrid1.cells[ACol, ARow] := Form8.Caption; end; end; end;
三、DateTimePicker1失去焦点
procedure TForm7.DateTimePicker1Exit(Sender: TObject); begin with Sender as TDateTimePicker do begin Hide; with StringGrid1 do cells[Col, Row] := DateToStr(DateTimePicker1.Date); end; end;
四、ComboBox1失去焦点
procedure TForm7.ComboBox1Exit(Sender: TObject); begin with Sender as TComboBox do begin Hide; if itemindex >= 0 then begin with StringGrid1 do cells[Col, Row] := items[itemindex]; end; end; end;
效果展示
标签:do,begin,end,ACol,ARow,ComboBox,单元格,StringGrid,Sender 来源: https://www.cnblogs.com/liessay/p/16228372.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。