Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

VCL help .....TListView....

luckyboyluckyboy Member Posts: 105
[b][red]This message was edited by luckyboy at 2005-11-21 20:49:7[/red][/b][hr]
Important to know that i use C++ Builder not Delphi.

i need a complete sorce code for sorting the TListView when column click.
The list contain only tow columns in report style.

My program intend to list all students names and their numbers to do some operations which i can take care.
First column is numbers #
Second column is Student Name.
i need when column clicked the list sorts all names alphapitically and when clicked again it sorts it in decending order.
:).

Comments

  • bilderbikkelbilderbikkel Member Posts: 754
    Hello Luckyboy,

    Check the Help better next time, I copy-pasted nearly all of this from two Help file examples: 'TCustomListView::AlphaSort' and 'Column, Items, ViewStyle, SmallImages, LargeImages, ImageIndex, AddObject, Objects example'.

    Unit1.cpp:
    [code]
    //Unit1.cpp
    __fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
    {
    ColumnToSort = 0;
    }
    //---------------------------------------------------------------------------

    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
    TListItem *pItem;
    TListColumn *pColumn;
    // Create a ListView item for each image in the ImageList
    ListView1->SmallImages = ImageList1;
    ListView1->LargeImages = ImageList1;
    for (int i = 0; i < ImageList1->Count; i++)
    {
    pItem = ListView1->Items->Add();
    pItem->Caption = "#" + IntToStr(i);
    pItem->ImageIndex = i;
    pItem->SubItems->Add("Student" + IntToStr(ImageList1->Count-i));
    }
    // Create two columns to show during viewing as vsReport
    pColumn = ListView1->Columns->Add();
    pColumn->Caption = "Number";
    pColumn = ListView1->Columns->Add();
    pColumn->Caption = "Student";
    // Add View styles and constants to the Combo Box
    ComboBox1->Items->AddObject("vsIcon", (TObject *)vsIcon);
    ComboBox1->Items->AddObject("vsList", (TObject *)vsList);
    ComboBox1->Items->AddObject("vsReport", (TObject *)vsReport);
    ComboBox1->Items->AddObject("vsSmallIcon", (TObject *)vsSmallIcon);
    // Display first item in the Combo Box
    ComboBox1->ItemIndex = 0;

    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::ComboBox1Change(TObject *Sender)
    {
    ListView1->ViewStyle = (TViewStyle) ComboBox1->Items->Objects[ComboBox1->ItemIndex];

    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::ListView1Compare(TObject *Sender, TListItem *Item1,
    TListItem *Item2, int Data, int &Compare)
    {
    if (ColumnToSort == 0)
    Compare = CompareText(Item1->Caption,Item2->Caption);
    else
    {
    int ix = ColumnToSort -1;
    Compare =
    CompareText(Item1->SubItems->Strings[ix], Item2->SubItems->Strings[ix]);
    }
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::ListView1ColumnClick(TObject *Sender,
    TListColumn *Column)
    {
    ColumnToSort = Column->Index;
    ((TCustomListView *)Sender)->AlphaSort();

    }
    //---------------------------------------------------------------------------
    [/code]

    Unit1.cpp
    [code]
    //---------------------------------------------------------------------------

    #ifndef Unit1H
    #define Unit1H
    //---------------------------------------------------------------------------
    #include
    #include
    #include
    #include
    #include
    #include
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published: // IDE-managed Components
    TListView *ListView1;
    TButton *Button1;
    TImageList *ImageList1;
    TComboBox *ComboBox1;
    void __fastcall FormCreate(TObject *Sender);
    void __fastcall ComboBox1Change(TObject *Sender);
    void __fastcall ListView1Compare(TObject *Sender, TListItem *Item1,
    TListItem *Item2, int Data, int &Compare);
    void __fastcall ListView1ColumnClick(TObject *Sender,
    TListColumn *Column);
    private: // User declarations
    int ColumnToSort;
    public: // User declarations
    __fastcall TForm1(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    //---------------------------------------------------------------------------
    #endif
    [/code]

    Have fun with it,
    bilderbikkel

  • bilderbikkelbilderbikkel Member Posts: 754
    Did it work? Or did complications arise?

    See ya,
    bilderbikkel

  • luckyboyluckyboy Member Posts: 105
    : Did it work? Or did complications arise?
    :
    : See ya,
    : bilderbikkel
    :
    :
    Every thing is OK
    Thank you very much
    By the way how many CDs has Borland CBuilder 6.0 Enterprize Eddition?
    i found them on Edonkey as 7 cds but my friend told me it's fake since they are 3 cds only.
    if you know any link to download all CDs please tell me about it.
    OFCOURSE WITH CRACK ;)
    See ya,
    M-Nasim (Lucky boy)
  • bilderbikkelbilderbikkel Member Posts: 754
    : By the way how many CDs has Borland CBuilder 6.0 Enterprize Eddition?
    Mine is on one.

    : if you know any link to download all CDs please tell me about it.
    I bought mine in a store, as it is illegal to copy software. You can download a Trial version for free on www.borland.com.

    See ya
    bilderbikkel

  • luckyboyluckyboy Member Posts: 105
    : I bought mine in a store, as it is illegal to copy software. You can download a Trial version for free on www.borland.com.
    :
    :
    :
    I know that is illegal, but I have no money, so I downloaded one with crack.

    See ya,
    M-Nasim

Sign In or Register to comment.