Search code examples
c++wxwidgets

Need code for wxListCtrl change to working code for virtual style wxListCtrl


I am new in c++ and I use for GUI wxWidget. My question is how this code for wxListCtrl change to working code for virtual ListCtrl...

now my code is below and work but I have to try with virtual style

wxString SQL = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + table + "'";

    int gstate = mysql_query(conn,SQL);
        if(!gstate){
            res = mysql_store_result(conn);
            int num = 0;

            lcData->SetColumnWidth(0,wxLIST_AUTOSIZE_USEHEADER);
            lcData->InsertColumn(0,"rb.");

            while(row = mysql_fetch_row(res)){
                lcData->SetColumnWidth(num+1, wxLIST_AUTOSIZE_USEHEADER);
                lcData->InsertColumn(num+1,row[0]);

                num++;
            }

            if(res != NULL)
                mysql_free_result(res);

        }
    SQL = tcSQL->GetValue();

    tcLog->AppendText(SQL+"\n");
    gstate = mysql_query(conn,SQL);

            if(!gstate){
                res = mysql_store_result(conn);
                long num_field = mysql_num_fields(res);

                   long num = 0;
                lcData->SetColumnWidth(0,40);

                while(row = mysql_fetch_row(res)){

                    lcData->InsertItem(num, wxString::Format(_T("%4d"),num+1));

                    for(long i = 0; i < num_field; i++){

                        lcData->SetItem(num,i+1,row[i] );

                    }

                    num++;
                }

                if(res != NULL)
                    mysql_free_result(res);

Where I compiling the program and run I have this error : SharedScreens

Thx. YuMERA


Solution

  • The idea of a virtual wxListCtrl is that you don't put the data into it, but provide the data on request, when the control needs it. So to use the virtual control, you need to change the structure of your code and avoid getting all the items from the database in the first place and, instead, retrieve them on demand from your overridden OnGetItemText() method. Of course, in order to be able to override it, you must derive your own class from wxListCtrl first and you also need to tell the control how many items is it going to have (which you would obtain from select count(*) ... query in your case).