delphi – 限制TDBGrid中的inplace编辑器的最大文本长度
发布时间:2020-12-15 09:07:37 所属栏目:大数据 来源:网络整理
导读:如何在TDBGrid中限制inplace编辑器的最大文本长度? (德尔福柏林) 数据类型是Float. 解决方法 TDBGrid中的inplace编辑器将通过调用更新其内容 procedure TInplaceEdit.UpdateContents;begin Text := ''; EditMask := Grid.GetEditMask(Grid.Col,Grid.Row); T
如何在TDBGrid中限制inplace编辑器的最大文本长度? (德尔福柏林)
数据类型是Float. 解决方法
TDBGrid中的inplace编辑器将通过调用更新其内容
procedure TInplaceEdit.UpdateContents; begin Text := ''; EditMask := Grid.GetEditMask(Grid.Col,Grid.Row); Text := Grid.GetEditText(Grid.Col,Grid.Row); MaxLength := Grid.GetEditLimit; end; GetEditMask的实现方式如下: function TCustomDBGrid.GetEditMask(ACol,ARow: Longint): string; begin Result := ''; if FDatalink.Active then with Columns[RawToDataColumn(ACol)] do if Assigned(Field) then Result := Field.EditMask; end; 和GetEditLimit像这样: function TCustomDBGrid.GetEditLimit: Integer; begin Result := 0; if Assigned(SelectedField) and (SelectedField.DataType in [ftString,ftWideString]) then Result := SelectedField.Size; end; 在那里,您有多种方法可以达到我想要的行为. >对要限制的字段使用TField 方法1的代码可能如下所示: // Opening of dataset ... DataSet.FieldByName('FloatField').EditMask := '00.00'; 这将掩盖在小数分隔符之前和之后需要两位数.有关面具的更多信息,请参见 方法2: uses Data.DB,Vcl.DBGrids; type TMyDBGrid = class(TDBGrid) protected function GetEditLimit: Integer; override; end; implementation { TMyDBGrid } function TMyDBGrid.GetEditLimit: Integer; begin Result := inherited GetEditLimit; if (Result = 0) and Assigned(SelectedField) and (SelectedField.DataType = ftFloat) then Result := 5; // Whatever you decide end; 就像kobik建议的那样,你可以将这个类用作插入类.为此,添加TDBGrid = class(TMyDBGrid);在您要使用该网格的单元中.如果您在要使用它的同一单元中声明TMyDBGrid,请使类型引用清除TMyDBGrid = class(Vcl.DBGrids.TDBGrid). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |