不同的用户登陆上来,选择设置不同需求的StringGrid显示的列,例如一个StringGrid:
T1 T2 T3 T4
------------------
a b b t
t s ts j
i e k op
...用户1登陆上来,他需要显示
T1 T2 T3
-------------
a b b
t s ts
i e k
...用户2登陆上来,他需要显示
T1 T3 T4
----------------
a b t
t ts j
i k op
...用户3登陆上来,他需要显示
T2 T3 T4
-------------
b b t
s ts j
e k op
...
现在没有什么思路,怎么完成,请大家多多发言提示,多谢!
up有分!
T1 T2 T3 T4
------------------
a b b t
t s ts j
i e k op
...用户1登陆上来,他需要显示
T1 T2 T3
-------------
a b b
t s ts
i e k
...用户2登陆上来,他需要显示
T1 T3 T4
----------------
a b t
t ts j
i k op
...用户3登陆上来,他需要显示
T2 T3 T4
-------------
b b t
s ts j
e k op
...
现在没有什么思路,怎么完成,请大家多多发言提示,多谢!
up有分!
然后根据你的权限设置stringgrid的你不显示的列的宽度为0,
这样就不影响你后边的代码了!
if 1 then
begin
StringGrid.Cells[0,0]:=t1;StringGrid.Cells[0,1]:=t2;StringGrid.Cells[0,2]:=t3;StringGrid.Cells[0,3]:=t4;
end;
if 2 then
begin
StringGrid.Cells[0,0]:=t1;StringGrid.Cells[0,1]:=t2;StringGrid.Cells[0,2]:=t3;StringGrid.Cells[0,3]:=t4;
end;
实际上定几个数组 或者Stringlist 用for i:=0 to x do StringGrid.Cells[0,i]:=Array[i];就搞定呢//对第一列用数组赋值
TclssCustmInfo=class
protected
m_iId:integer ;
m_arrHeadInfo:array of String ;
public
constructor create(id:integer ;arrHead:array of string) ;
public
procedure m_WriteToDesGrdHead(clssdesGrid:TStringGrid) ;
end ;constructor TclssCustmInfo.create(id:integer ;arrHead:array of string);
var
iLen : integer ;
begin
inherited create ;
m_iId:=id ;
iLen:= high(arrHead)+1 ;
setLength(m_arrHeadInfo,iLen) ;
for iLen:=0 to high(arrHead) do
begin
m_arrHeadInfo[iLen]:=arrHead[iLen] ;
end;
end ;procedure TclssCustmInfo.m_WriteToDesGrdHead(clssdesGrid:TStringGrid) ;
var
i:integer ;
begin
if clssdesGrid=nil then exit ;
clssDesGrid.ColCount := high(m_arrHeadInfo)+1 ;
clssDesGrid.RowCount := 1 ;
clssDesGrid.Rows[0].Clear ;
for i:=0 to high(m_arrHeadInfo) do
begin
clssDesGrid.Rows[0].Add( m_arrHeadInfo[i]) ;
end ;
end; //测试代码
procedure TForm1.Button2Click(Sender: TObject);
var
strHead1:array[0..5] of string ;
clss:TclssCustmInfo ;
begin
//
clss:=TclssCustmInfo.create(1,['第一列','第2列','第3列']);
clss.m_WriteToDesGrdHead(StringGrid1);
end;
由于这个系统中需要定制显示列的StringGrid很多,我也考虑的也是不想影响后面以完成的代码。
我觉得你说的可行,用隐藏列的方法,用户自己选择需要显示的列,记忆下来,下次用户登陆这个窗口时把不需要显示的列宽设置为0。
这个处理我打算在StringGrid的OnMouseMove事件上做,因为即使窗口初始化时设置列宽为0,用户还是可以用鼠标把这一列拉出显示的。大家给点意见?