当前位置:首页 > 网络编程 > 软件语言 > DELPHI > Dbgrid 中表字段所在的列序号

Dbgrid 中表字段所在的列序号

点击次数:53 次 发布日期:2008-11-09 08:36:57 作者:源代码网
源代码网推荐
广告载入中

源代码网整理以下//--------------------------------------------------------------------------------
// 功能:返回表字段在 DBGrid 列中的序号,首序号为0
// 参数: pDbGrid:TDbGrid; DBGrid
// pcFieldName : string 数据表字段名,字段名不区分大小写
// 返回:当表字段在 DBGrid 中存在时,返回表字段所在的列的序号,首序号为0
// 否则,返回 -1
//例子:DbGrid1.SelectedIndex := GetDbGridColumnIndex( DbGrid1, "Price" );
//--------------------------------------------------------------------------------
Function GetDbGridColumnIndex( pDbGrid:TDbGrid; pcFieldName : string ):integer;
var nFldLoop : integer ;
cFldName : string ;
begin
Result := -1 ;
For nFldLoop := 0 to pDbGrid.Columns.Count-1 do
begin
cFldName := pDbGrid.Columns[nFldLoop].FieldName ;
If uppercase(pcFieldName) = uppercase( cFldName ) then
begin
Result := nFldLoop ;
exit ;
end;
end;
end;

源代码网整理以下例子:

源代码网整理以下 DbGrid1.SelectedIndex := GetDbGridColumnIndex( DbGrid1, "Price" );
将DbGrid1的当前列定位到字段Price上。



源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华