//--------------------------------------------------------------------------------
// 功能:将 DbGrid 当前列定位到某字段上。
// 参数: pDbGrid:TDbGrid; DBGrid
// pcFieldName : string 数据表字段名,字段名不区分大小写
// 返回:当表字段在 DBGrid 中存在时,返回表字段所在的列的序号,首序号为0
// 否则,返回 -1
// 引用:GetDbGridColumnIndex( );
// 例如:SetDbGridColumn( DbGrid1, 'Price' );
//--------------------------------------------------------------------------------
Function SetDbGridColumn( pDbGrid:TDbGrid; pcFieldName : string ):integer;
var nCol : integer ;
begin
Result := GetDbGridColumnIndex( pDbGrid, pcFieldName );
if nCol >= 0 then pDbGrid.SelectedIndex := Result ;
end;
例子:
SetDbGridColumn( DbGrid1, 'Price' );
将DbGrid1的当前列定位到字段Price上。
博客介绍了一个将DbGrid当前列定位到某字段上的函数SetDbGridColumn。该函数接收DBGrid和数据表字段名作为参数,若表字段在DBGrid中存在,返回其所在列序号,否则返回 -1,并给出了使用示例。
2542

被折叠的 条评论
为什么被折叠?



