When we use Stringgrid, we often need to clear the contents of all the cells, and I use the following methods:
grdFileList->RowCount=1; //设置总行数,有一行标题行
for (irow=0; irow < OpenDialog1->Files->Count; irow++) //这个例子是将对话框中选择的文件放到GRID中
{
grdFileList->RowCount++; //总行数增加
grdFileList->Rows[irow+1]->Clear(); //清空当前行所有单元格内容
grdFileList->Cells[0][irow+1] = ""; //第0列一般为选择列标记
grdFileList->Cells[1][irow+1] = ExtractFileName(OpenDialog1->Files->Strings[irow]); //文件名
grdFileList->Cells[2][irow+1] = OpenDialog1->Files->Strings[irow]; //含路径文件名
....
....
}
if (grdFileList->RowCount>1)
grdFileList->FixedRows = 1; //第一行为固定标题行,将其变为灰色
Conclusion: This design program will ensure that each new line added is up-to-date or blank.
Note: If you use grdfilelist->rowcount=1; only, the number of rows becomes long, and the old content is displayed.
Other: The above is debugged in C + + builder6/c++ Builder 2009.