none
Dynamic ListView RRS feed

  • Question

  •  

    Hi I am using C++/CLI in VC 2008..

    I want to create a dynamic ListView which changes ColumnHeaders (adds or deletes) as I call various methods..

    How to do that??

    The Column Headers are added in the beginning of the windows generated code and then when I want to add it again(using gcnew), it throws error (obviously it would)..

    Can anyone suggest me a workaround??

    Tuesday, April 22, 2008 10:57 AM

Answers

  • Hi,

     

    Would you please post a snippet code and error message in order to find the error cause?

     

    By the way, to add a column to the ListView control, just call the Add method of

    ListView.Columns.

     

    Here is sample code, hope it helps!

    Code Snippet

    public ref class Form1 : public System::Windows::Forms::Form

    {

    //…other codes

    //…..

     

    //define ListView varaible

    private: System::Windows::Forms::ListView ^lstView;

     

    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e)

    {

                       //Create the ListView control    

                       this->lstView=gcnew System::Windows::Forms::ListView();

                      //Set its properties

                       this->lstView->Size=System::Drawing::Size(300, 200);

                       this->lstView->Location=System::Drawing::Point(50,50);

                                   

                       this->lstView->View=System::Windows::Forms::View::Details;

                       //Add columns

                       this->lstView->Columns->Add(L"Header1",60);

                       this->Controls->Add(lstView);

     

              }

    private: System::Void btnAdd_Click(System::Object^  sender, System::EventArgs^  e)

    {

                       //Add columns

                       this->lstView->Columns->Add(L"Header2",60);   

    }

    }

     

     

    For detail information of ListView, you can refer to

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.listview.aspx

     

    Hope it helps!

     

    Thursday, April 24, 2008 8:55 AM