如何获得DBGRIRD的所选择的多行
如何获得DBGRIRD的所选择的多行
[解决办法]
TDataSet *pDS = DBGrid1->DataSource->DataSet;
for (int i=0; i < DBGrid1->SelectedRows->Count; i++)
{
pDS->GotoBookmark((void*)DBGrid1->SelectedRows->Items[i].c_str());
...
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (DBGrid1->SelectedRows->Count > 0)
{
AnsiString s = "";
TDataSet *pDS = DBGrid1->DataSource->DataSet;
for (int i=0; i < DBGrid1->SelectedRows->Count; i++)
{
pDS->GotoBookmark((void *)DBGrid1->SelectedRows->Items[i].c_str());
for (int j = 0; j < pDS->FieldCount; j++)
{
if (j>0)
s = s+", ";
s = s + pDS->Fields->Fields[j]->AsString;
}
ListBox1->Items->Add(s);
s = "";
}
}
}