cxgrid的多選記錄 修改記錄問題 vga 發表於2011-06-18 08:08 瀏覽(60)
評論(1) 分類:我的日記
舉報
cxgrid 雙擊 擷取所點擊行的內容
建立view的 optionsselection->cellselect 設定為false ,才能觸發雙擊事件
案例:
procedure TForm_Child_Archive.cxGrid1DBTableView1CellDblClick(
Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo;
AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin3
////取得所雙擊列的列表頭名稱 ACellViewInfo.Item.Index 為所雙擊列
//ShowMessage(cxGrid1DBTableView1.Columns[ACellViewInfo.Item.Index].Caption);
with cxGrid1DBTableView1.DataController do
begin
//取某行某列的值 ,取第5列,參數4
ShowMessage(Values[FocusedRecordIndex,4]);
end;
end;
其他:
如果不需要對儲存格進行選擇可:設定CXGrid的TableView對象的OptionsSelection->CellSelect 為False;
如果需要對儲存格進行選擇可:設定CXGrid的TableView對象的OptionsData中的全部屬性 為False;
cxgrid的多選記錄 修改記錄問題
cxgrid多選 , 有可能是連續的,有可能是隔了其他記錄的
cxgrid 把 cxGrid1DBTableView1——》 optionselection——》multiselect設為true就可以了
GridView.DataController.DataModeController.GridMode=True;
修改選中的記錄中一個欄位 :
sample1:
procedure TForm1.btnSelectValueClick(Sender: TObject);
var
I, J:Integer;
begin
for I:=0 to tvcxgd1DBTableView1.DataController.GetSelectedCount-1 do begin
J:=tvcxgd1DBTableView1.DataController.GetSelectedRowIndex(I);
ShowMessage(VarToStr(tvcxgd1DBTableView1.DataController.GetValue(J,0)));
end;
end; sample2:
Var
i:integer;
begin
For i:=0 To cxGrid1DBTableView1.Controller.SelectedROwCount-1 Do
begin
cxGrid1dbtableview1.Controller.FocusedRow:=cxGrid1dbtableview1.Controller.SelectedRows[i];
Adoquery1.Edit;
Adoquery1.FieldByName('DeptName').AsString:=Edit1.Text
Adoquery1.Post;
end;
end;
摘自:
摘自:
進行cxgrid多行記錄刪除
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
sID : string;
adotmp : TADOQuery;
begin
//Values[0] 為欄位a
//Values[1] 為識別欄位
//cxgrdItemList 為cxGrid
sID := '0';
for i := 0 to cxgrdItemList.DataController.Controller.SelectedRecordCount - 1 do
begin
if cxgrdItemList.DataController.Controller.SelectedRecords[i].Values[0] = True then
continue;
sID := sID + ', ' + cxgrdItemList.DataController.Controller.SelectedRecords[i].Values[1];
end;
adotmp := TADOQuery.Create(nil);
with adotmp do
try
{自己寫
Connection := ;
}
sql.Text := 'delete from yTbName where ID in (' + sID + ')';
ExecSQL;
finally
free;
//重新整理一下cxgrid的dataset;
end;
end
http://wo.115.com/?ct=detail&id=32100&bid=1408771