如何在devexpress VCL for Delphi中转换此代码

时间:2016-02-17 13:31:00

标签: c# delphi devexpress

您好我想将此代码转换为VCL Delphi:

    // Create an empty list.
ArrayList rows = new ArrayList();
// Add the selected rows to the list.
for (int i = 0; i < gridView1.SelectedRowsCount; i++) {
   if (gridView1.GetSelectedRows()[i] >= 0)
      rows.Add(gridView1.GetDataRow(gridView1.GetSelectedRows()[i]));
}
try {
   gridView1.BeginUpdate();
   for (int i = 0; i < rows.Count; i++) {
      DataRow row = rows[i] as DataRow;
      // Change the field value.
      row["Discontinued"] = true;                             
   }
}
finally {
   gridView1.EndUpdate();
} 

我试图做同样的事情但是在VCL中没有SelectedRowsCount或GetSelectedRows我在哪里可以找到?

1 个答案:

答案 0 :(得分:2)

只是做你找到的程序: 发件人是您的gridView1,isConnected是您的列的值。

procedure TForm1.ChangeColumn(Sender: TcxCustomGridTableView; isConnected: boolean);
var i: integer; AColumn: TcxCustomGridTableItem;
begin
  if ((TcxGridDBTableView(Sender).Controller.SelectedRecordCount=0)
    or (TcxGridDBTableView(Sender).Controller.SelectedRecords[0] = nil))
  then exit;

  AColumn:= TcxGridDBTableView(Sender).GetColumnByFieldName('Discontinued');
  if AColumn = nil then exit;

  TcxGridDBTableView(Sender).DataController.BeginFullUpdate;
  try
    for i:= 0 to TcxGridDBTableView(Sender).Controller.SelectedRecordCount-1 do
    begin
        TcxGridDBTableView(Sender).Controller.SelectedRecords[i].Values[AColumn.index] := isConnected;
    end;

  finally
    TcxCustomGridTableView(Sender).DataController.EndFullUpdate;
  end;
end;