让搜索框随表格位置变化
在做一个数据录入的时候,经常用到,有些数据需要从代码表中进行录入,但一般的表格控件又不支持根据助记码进行搜索,保存编码,所以一般会设计成,选中某列以后,根据需要自动弹出代码列表供用户选择,下面的例子就是序代码表弹出的位置,可以处由变换的例子,当然可以根据自己需要修改什么时候可见,什么时候不可见:
procedure TForm1.vwFocusedItemChanged(Sender: TcxCustomGridTableView; APrevFocusedItem, AFocusedItem: TcxCustomGridTableItem); begin //编辑格left MyLeft:=AFocusedItem.FocusedCellViewInfo.Bounds.left; myPos:=point(MyLeft,MyTop); //转换位置为相对于form的x,y myPos:=cxGrid1.ClientToParent(myPos,Self); //计算srchGrid是否超出form的下边界 if (MyPos.Y+1+SrchGrid.Height)<=Self.Height then SrchGrid.Top:=myPos.y+1 else SrchGrid.Top:=MyPos.Y-1-cellHeight-SrchGrid.Height; SrchGrid.Left:=myPos.X; end; procedure TForm1.vwFocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean); begin //行高 CellHeight:=AFocusedRecord.ViewInfo.Bounds.Bottom- AFocusedRecord.ViewInfo.Bounds.Top; //编辑格bottom MyTop:=AFocusedRecord.ViewInfo.Bounds.Bottom; myPos:=point(MyLeft,MyTop); //转换位置为相对于form的x,y myPos:=cxGrid1.ClientToParent(myPos,Self); //计算srchGrid是否超出form的下边界 if (MyPos.Y+1+SrchGrid.Height)<=Self.ClientHeight then SrchGrid.Top:=myPos.y+1 else SrchGrid.Top:=MyPos.Y-1-cellHeight-SrchGrid.Height; SrchGrid.Left:=myPos.X; |