星期三, 5月 26, 2010

cxgrid要能取消選擇的作法

cxgrid 的optionSelection屬性MultiSelect設為True

cxGDBTV1MouseDown事件設定

procedure TfrmDataSwSelect.cxGDBTV1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
i : integer;
begin

i := cxGDBTV1.DataController.FocusedRowIndex;
cxGDBTV1.DataController.ClearSelection; //清除
cxGDBTV1.DataController.SelectRows(i,i);
end;

cxGDBTV1KeyDown事件設定

procedure TfrmDataSwSelect.cxGDBTV1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssShift in Shift) then //shift要失效
Key :=0;
end;

清楚選取用

cxGDBTV1.DataController.ClearSelection;

初始時將cxgrid移到特定的選擇可用

ADOQuery1.First;
if ADOQuery1.Locate('swid', swid, []) then
iIndex := ADOQuery1.RecNo-1
else
iIndex:=-1;
if iIndex>=0 then
cxGDBTV1.DataController.SelectRows(iIndex,iIndex);