Unigui 中 TUniDBLookupComboBox 使用的问题
TUniDBLookupComboBox 在 unidbgrid 中使用的时候会产生一个问题就是 grid 对应单元格会显示keyvalue ,而不是 text ,这样极不友好,反正我是感觉很不爽,所以花了点时间找下原因。后来想到 是/否 显示的方法,所以就跟着一路的跳,跳到了目标代码处。修改了一下,并测了还行,就发上来了,我估计有很多人和我一样需要。
不讲没用的,直接上方法
源文件:uniDBUtils.pas
目标函数:FieldValueToJS
添加如下代码:
function FieldValueToJS(ACol: TUniBaseDBGridColumn; F: TField; ForceRaw: Boolean=False): string;
var
S : string;
SArr : TUniStringArray;
bVal : Boolean;
DisplayText:string;
begin
Result := '""';
if (not (F is TBinaryField)) and (not (F is TArrayField)) then
begin
if VarIsNull(F.Value) then Exit;
if (not (F is TBooleanField)) and Assigned(ACol) and ACol.CheckBoxField.Enabled and (not ACol.CheckBoxField.BooleanFieldOnly) then
begin
bVal := False;
if not VarIsNull(F.Value) then
begin
S := F.Value;
SArr := ExtractBooleanValues(ACol.CheckBoxField.FieldValues);
if (Length(SArr) > 0) and SameText(S, SArr[0]) then bVal := True;
end;
Result := UniBoolToStr(bVal);
Exit;
end
else {添加下面的代码在当前位置开始}
begin
if Assigned(ACol) and Assigned(ACol.Editor) and (ACol.Editor is TUniDBLookupComboBox) then
begin
with (ACol.Editor as TUniDBLookupComboBox) do
begin
if (ListSource <> nil) and (KeyField <> '') and (ListField <> '') then
begin
DisplayText := F.DisplayText;
if not VarIsNull(F.Value) then
begin
S := F.Value;
if ListSource.DataSet.Locate(KeyField, S, []) then
DisplayText := ListSource.DataSet.FieldByName(ListField).AsString
else
DisplayText := '';
end;
Result := StrToJS(DisplayText);
Exit;
end;
end;
end;
end;
end;