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

請問stringgrid的問題

尚未結案
opium
一般會員


發表:22
回覆:11
積分:6
註冊:2003-02-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-05-11 14:27:54 IP:218.162.xxx.xxx 未訂閱
各位先進安安 小弟想請問如果我的stringgrid設定為10列 因為需要有半法在第2和第3中間在挿進新的一列嗎? 或是刪掉其中一列呢? 謝謝各位指導 「好程式應與他人分享!」無疑是至理名言。 -Richard Stallman,GNU 計畫的創辦人 GNU宣言 發表人 - opium 於 2005/05/11 15:17:52
RedSnow
版主


發表:79
回覆:1322
積分:845
註冊:2003-12-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-05-11 20:47:10 IP:218.19.xxx.xxx 未訂閱
opium 您好:    以下資料摘自vcl.components.using Mini FAQ:    
(Q4.4)  How do I insert/remove a row or column in a TStringGrid?     (A4.4)  Implement this functionality manually by manipulating the 
        RowCount or ColCount property, then shifting the contents of 
        the surrounding cells.  The following function can be used to 
        insert a row.  Inserting a column, or deleting a row or column 
        can be accomplished via a similar technique.     void __fastcall InsertRow(TStringGrid *StringGrid, long AfterIndex) 
{ 
    SNDMSG(StringGrid->Handle, WM_SETREDRAW, false, 0); 
    try 
    { 
        int row_count = StringGrid->RowCount; 
        StringGrid->RowCount = row_count   1;             for (int row = row_count; row > AfterIndex   1; row--) 
            StringGrid->Rows[row] = StringGrid->Rows[row - 1];             StringGrid->Rows[AfterIndex   1]->Clear(); 
    } 
    catch (...) 
    { 
        SNDMSG(StringGrid->Handle, WM_SETREDRAW, true, 0); 
    } 
    SNDMSG(StringGrid->Handle, WM_SETREDRAW, true, 0);         RECT R = StringGrid->CellRect(0, AfterIndex); 
    InflateRect(&R, StringGrid->Width, StringGrid->Height); 
    InvalidateRect(StringGrid->Handle, &R, false); 
} 
以上的函式可新增一個空的橫行 (Row) 到 StringGrid 指定行的下方,使用方式如下: InsertRow(StringGrid1, 2); 上例是在 StringGrid1 的第 2 行之下插入一個空行,刪除的部份請參照範例比照辦理,您參考一下。 發表人 - RedSnow 於 2005/05/11 21:01:20
opium
一般會員


發表:22
回覆:11
積分:6
註冊:2003-02-23

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-05-12 07:59:35 IP:218.162.xxx.xxx 未訂閱
謝謝 rednosw 的指導    昨晚我想到的方法
  int R;
  R=StringGrid2->Row;
  for(R;R<=counts;R  )
    StringGrid2->Cells[1][R]= StringGrid2->Cells[1][R 1];
利用for將資料往下或往上搬移 「好程式應與他人分享!」無疑是至理名言。 -Richard Stallman,GNU 計畫的創辦人 GNU宣言
系統時間:2024-05-14 7:20:13
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!