cxGrid使用记录

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;

摘自:http://topic.csdn.net/t/20041025/08/3487114.html

摘自:http://topic.csdn.net/t/20060113/09/4514294.html


进行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://hi.baidu.com/diy_era/blog/item/73b5ccdd6896dd385882dd12.html

原文地址:https://www.cnblogs.com/karkash/p/3085966.html