線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2593
推到 Plurk!
推到 Facebook!

如何刪除及插入 StringGrid 指定的某一個 Rows

 
erosme
初階會員


發表:5
回覆:44
積分:29
註冊:2002-12-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-02-12 00:38:56 IP:61.216.xxx.xxx 未訂閱
請問大家,    若不用搬移或覆蓋的方式來做. 要如何刪除 StringGrid 的某一個 Rows, 以及插入一個空白列.    Thanks.
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-02-12 09:10:47 IP:147.8.xxx.xxx 未訂閱
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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-02-12 15:53:25 IP:61.139.xxx.xxx 未訂閱
以下是我自己写的方法,需要在头文件中声明 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; iRowCount-1; i ) { sGrid->Rows[i] = sGrid->Rows[i 1]; } sGrid->RowCount = sGrid->RowCount -1; } else { sGridClear(sGrid,1); } } 读书永远也不晚
------
读书永远也不晚
BGman
初階會員


發表:28
回覆:85
積分:42
註冊:2003-01-10

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-02-12 16:17:32 IP:211.22.xxx.xxx 未訂閱
目前我只研究出像dsyyybw 這種用搬移的方法 理論上直接應用Insert、Delete這兩支Method,就能達到erosme的要求 可是我一直研究不出來以下的寫法: StringGrid1->Rows[0]->Insert(0); StringGrid1->Rows[0]->Delete(0); 為何都會出現錯誤? 眾志成城,大家一起幫忙想吧!
erosme
初階會員


發表:5
回覆:44
積分:29
註冊:2002-12-23

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-02-13 20:14:23 IP:61.216.xxx.xxx 未訂閱
引言: 我之前也試過 StringGrid1->Rows[10]->Insert(10); 的寫法: 但我不了解Rows[10] 既已指定為 10 , 那 Insert() 為何又要指定. 且若改為 StringGrid1->Rows->Insert(10); 或 StringGrid1->Rows[10]->Insert(); 則 compiler 時會有Error. 真的不知 Insert() , Delete() 到底要如何使用.
系統時間:2024-04-29 4:21:08
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!