cxGrid单元格获得输入焦点

cxGrid单元格获得输入焦点,主要用于数据集类的表格视图,如TcxGridDBTableView与TcxGridDBBandedTableView

很简单的一个函数,用于快速获取焦点来输入数据:

procedure cxGridViewSetFocus(FieldName: string; GridView: TcxCustomGridTableView);
var
  cxGrid: TcxGrid;
  AItem: TcxCustomGridTableItem;
begin
  cxGrid := TcxGrid(GridView.Control);
  if cxGrid.ActiveLevel <> GridView.Level then
    cxGrid.ActiveLevel := TcxGridLevel(GridView.Level);
  if (cxGrid.Focused=False)and(cxGrid.CanFocus) then
    cxGrid.SetFocus;

  with TcxGridDBDataController(GridView.DataController) do
  begin
    AItem := GetItemByFieldName(FieldName);
    if AItem <> nil then
    begin
      if AItem.Visible = False then
        AItem.Visible := True;
      AItem.Focused := True;
      GridView.Controller.EditingController.ShowEdit(AItem);
    end;
  end;
end;


你可能感兴趣的:(cxgrid,获取输入焦点,DevExpressVCL)