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

請問STRINGGRID可以做排序嗎?

尚未結案
answer
一般會員


發表:17
回覆:10
積分:5
註冊:2004-05-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-05-18 18:48:44 IP:211.72.xxx.xxx 未訂閱
LISTVIEW可以點標題來做排序的功能,那STRINGGRID可以ㄇ,有個重要的問題是要整個ROW一起排序,就是說 a | b | c a | b | c 1 aa bb cc 1 aa bb cc 2 a1 b1 c1 =>3 a2 b2 c2 3 a2 b2 c2 2 a1 b1 c1 希望可以建議我依些做法,謝謝....拜託ㄌ
answer
一般會員


發表:17
回覆:10
積分:5
註冊:2004-05-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-05-19 10:21:02 IP:61.219.xxx.xxx 未訂閱
我現在把同一個ROW當作一個STRUCT的陣列EX:SORT[0],那我陷再想要依照這個陣列裡面某一個STRING來做整個陣列排序,在重新呈現在STRINGGRID上面,問題是如何將整個陣列配合某一個STRING來排列。謝
lijenyun
一般會員


發表:3
回覆:19
積分:9
註冊:2003-06-22

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-05-19 21:18:03 IP:210.64.xxx.xxx 未訂閱
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
    StringGrid1->Cells[1][1] = "Acer";
    StringGrid1->Cells[1][2] = "IBM";
    StringGrid1->Cells[1][3] = "Compaq";
    StringGrid1->Cells[1][4] = "BenQ";        StringGrid1->Cells[2][1] = "1000";
    StringGrid1->Cells[2][2] = "5000";
    StringGrid1->Cells[2][3] = "3000";    }
//---------------------------------------------------------------------------    void __fastcall TForm1::StringGrid1MouseUp(TObject *Sender,
        TMouseButton Button, TShiftState Shift, int X, int Y)
{
    int ACol, ARow;
    StringGrid1->MouseToCell(X, Y, ACol,ARow);
    GetSort(StringGrid1, ACol);    }
//---------------------------------------------------------------------------    void TForm1::GetSort(TStringGrid *GenStrGrid, int ThatCol)
{   
    const char TheSeparator = '@'; // Define the Separator
    int CountItem = GenStrGrid->RowCount; // Give the number of rows in the StringGrid        TStringList *MyList = new TStringList; //Create the List        try
    {
        MyList->Sorted = False;            for (int I=1; I<=CountItem - 1;I  )
        {
            MyList->Add(GenStrGrid->Rows[I]->Strings[ThatCol]   TheSeparator   GenStrGrid->Rows[I]->Text);
          
        }            MyList->Sort(); //Sort the List            for (int K = 1 ; K<=MyList->Count;K  )
        {
            String MyString = MyList->Strings[(K - 1)]; //Take the String of the line (K – 1)
            int ThePosition = MyString.Pos(TheSeparator); //Find the position of the Separator in the String                //Eliminate the Text of the column on which we have sorted the StringGrid}
            String TempString = MyString.SubString(ThePosition   1,MyString.Length());                MyList->Strings[(K - 1)] = "";
            MyList->Strings[(K - 1)] = TempString;
        }            for (int J = 1; J<=CountItem - 1;J  )
            GenStrGrid->Rows[J]->Text = MyList->Strings[(J - 1)]; //Refill the StringGrid        }
    __finally
    {
        delete MyList;
    }
}    
參考網址 http://www.undu.com/Articles/990502f.html 發表人 - lijenyun 於 2004/05/19 23:24:56 發表人 - lijenyun 於 2004/05/19 23:26:17
answer
一般會員


發表:17
回覆:10
積分:5
註冊:2004-05-14

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-05-20 09:39:16 IP:211.23.xxx.xxx 未訂閱
謝謝這位高手,還有一個問題想要請問就是STRINGGRID的SCROLLING 內容不會跟著動ㄟ,可以交交我ㄇ
harrypp
中階會員


發表:7
回覆:124
積分:61
註冊:2006-08-31

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-07-02 11:24:08 IP:210.68.xxx.xxx 訂閱
用這方法會比較有效率 
<textarea class="cpp" rows="10" cols="60" name="code"> /////////////////////////////////////////////// ;;共12個欄位 20筆資料 ;;若想改第三個欄位為鍵值 for (I=0;I<20;I ) { AnsiString* strData, Key; strData=new AnsiString[12]; strData[I]=..... //輸入資料 Key=strData[5]; //以第五個欄位為鍵值 MyList->AddObject(Key, (TObject *)strData); } MyList->Sort(); //排序 /////////////////////////////////////////////// ;;若想改第三個欄位做排序 for (I=0;I<20;I ) { (TObject *)sTemp=MyList->Objects[I]; MyList->Strings[I]=sTemp[3]; //以第三個欄位為鍵值 } MyList->Sort(); //排序 /////////////////////////////////////////////// ;;讀出排序後的資料 for (I=0;I<20;I ) { (TObject *)sTemp=MyList->Objects[I]; for (J=0; J<12; J ) MyList->Strings[I]=sTemp[J]; } </textarea>
編輯記錄
harrypp 重新編輯於 2007-07-02 11:25:51, 註解 無‧
harrypp 重新編輯於 2007-07-02 11:26:55, 註解 無‧
harrypp 重新編輯於 2007-07-02 11:27:59, 註解 無‧
系統時間:2024-05-05 18:35:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!