如何刪除及插入 StringGrid 指定的某一個 Rows |
|
erosme
初階會員 發表:5 回覆:44 積分:29 註冊:2002-12-23 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
This is not a trivial task. You may find some 3rd part grid allowing insert/delete of a row. BTW, if you want to do it with the standard grid, I recommend drawing the grid cell yourself in the OnDrawCell event. For example, you can store your data in a list (e.g. TStringList) while rendering the text in the grid cells in your OnDrawCell event. Then by removing the data in the list (and adjust the RowCount of the grid) and do a Grid->Invalidate(), the row should be disappeared... Just my two cents.
|
dsyyybw
一般會員 發表:16 回覆:24 積分:8 註冊:2003-01-02 發送簡訊給我 |
以下是我自己写的方法,需要在头文件中声明
void sGridInsertCol(TStringGrid *sGrid,int CCol);
void sGridDelRow(TStringGrid *sGrid,int CRow); //在表格中插入列(CCol=-1在当前列插入,
// 否则在指定列插入,如果指定列大于总列数则添加一列到末尾)
void sGridInsertCol(TStringGrid *sGrid,int CCol)
{
int CurrentCol;
if(CCol == -1)
{
CurrentCol = sGrid->Col;
}
else
{
CurrentCol = CCol;
}
sGrid->ColCount = sGrid->ColCount + 1;
for(int col = sGrid->ColCount - 1; col > CurrentCol; col--)
{
sGrid->Cols[col] = sGrid->Cols[col - 1];
}
sGrid->Cols[CurrentCol]->Clear(); //删除行(CRow=-1删除当前行,
// 否则删除指定行,如果指定行大于总行数则删除最后一行)
void sGridDelRow(TStringGrid *sGrid,int CRow)
{
int CurrentRow;
if(sGrid->RowCount > sGrid->FixedRows + 1)
{
if(CRow == -1)
{
CurrentRow = sGrid->Row;
}
else
{
CurrentRow = CRow;
} for(int i=CurrentRow; i
------
读书永远也不晚 |
BGman
初階會員 發表:28 回覆:85 積分:42 註冊:2003-01-10 發送簡訊給我 |
|
erosme
初階會員 發表:5 回覆:44 積分:29 註冊:2002-12-23 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |