views:

28

answers:

0

I want to create a listView that have 8 groups (Group0,Group1,...) and six columns,the format like this way

Group0
XXX_0Y11_r    value  XXX_0Y11_w   value   ZZZ_(11) tt
XXX_0Y12_r    value  XXX_0Y12_w   value   ZZZ_(12) tt
XXX_0Y21_r    value  XXX_0Y21_w   value   ZZZ_(21) tt
XXX_0Y22_r    value  XXX_0Y22_w   value   ZZZ_(22) tt
QQQ_01        ss
QQQ_02        ss

Group1
XXX_1Y11_r    value  XXX_1Y11_w   value   ZZZ_(11) tt
XXX_1Y12_r    value  XXX_1Y12_w   value   ZZZ_(12) tt
XXX_1Y21_r    value  XXX_1Y21_w   value   ZZZ_(21) tt
XXX_1Y22_r    value  XXX_1Y22_w   value   ZZZ_(22) tt
QQQ_11        ss
QQQ_12        ss

...
....

i had no way to make it out ,, could you help take a look what's happened in my code? there is no compiler error in my code but it can't display as i wanted. i think the curpit should be in the function
private: void addOneComplexItem(int complexItemNum,int groupNum,ListViewGroup^ oneListGroup)

i guess there maybe some bug in cli/c++/listview ...please help me take a look many thanks.

here is the full code

#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;


namespace TextTest {

    /// <summary>
    /// Summary for TextGUI
    ///
    /// WARNING: If you change the name of this class, you will need to change the
    ///          'Resource File Name' property for the managed resource compiler tool
    ///          associated with all .resx files this class depends on.  Otherwise,
    ///          the designers will not be able to interact properly with localized
    ///          resources associated with this form.
    /// </summary>
    public ref class TextGUI : public System::Windows::Forms::Form
    {
    public:
        TextGUI(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~TextGUI()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::ListView^  myListview;
    private: System::Windows::Forms::ColumnHeader^  columnHeader_realName;
    private: System::Windows::Forms::ColumnHeader^  columnHeader_imagValue;
    private: System::Windows::Forms::ColumnHeader^  columnHeader_normName;



    private: System::Windows::Forms::ColumnHeader^  columnHeader_realValue;
    private: System::Windows::Forms::ColumnHeader^  columnHeader_imagName;
    private: System::Windows::Forms::ColumnHeader^  columnHeader_normValue;




    private: System::Windows::Forms::Button^  button_Fresh;

    protected: 

    protected: 




    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->myListview = (gcnew System::Windows::Forms::ListView());
            this->columnHeader_realName = (gcnew System::Windows::Forms::ColumnHeader());
            this->columnHeader_realValue = (gcnew System::Windows::Forms::ColumnHeader());
            this->columnHeader_imagName = (gcnew System::Windows::Forms::ColumnHeader());
            this->columnHeader_imagValue = (gcnew System::Windows::Forms::ColumnHeader());
            this->columnHeader_normName = (gcnew System::Windows::Forms::ColumnHeader());
            this->columnHeader_normValue = (gcnew System::Windows::Forms::ColumnHeader());
            this->button_Fresh = (gcnew System::Windows::Forms::Button());
            this->SuspendLayout();
            // 
            // myListview
            // 
            this->myListview->Alignment = System::Windows::Forms::ListViewAlignment::Default;
            this->myListview->Columns->AddRange(gcnew cli::array< System::Windows::Forms::ColumnHeader^  >(6) {this->columnHeader_realName, 
                this->columnHeader_realValue, this->columnHeader_imagName, this->columnHeader_imagValue, this->columnHeader_normName, this->columnHeader_normValue});
            this->myListview->FullRowSelect = true;
            this->myListview->GridLines = true;
            this->myListview->HeaderStyle = System::Windows::Forms::ColumnHeaderStyle::None;
            this->myListview->Location = System::Drawing::Point(0, -1);
            this->myListview->MultiSelect = false;
            this->myListview->Name = L"myListview";
            this->myListview->Size = System::Drawing::Size(698, 430);
            this->myListview->TabIndex = 0;
            this->myListview->TileSize = System::Drawing::Size(168, 34);
            this->myListview->UseCompatibleStateImageBehavior = false;
            this->myListview->View = System::Windows::Forms::View::Tile;
            // 
            // columnHeader_realName
            // 
            this->columnHeader_realName->Text = L"";
            // 
            // columnHeader_realValue
            // 
            this->columnHeader_realValue->Text = L"";
            this->columnHeader_realValue->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
            // 
            // columnHeader_imagName
            // 
            this->columnHeader_imagName->Text = L"";
            this->columnHeader_imagName->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
            // 
            // columnHeader_imagValue
            // 
            this->columnHeader_imagValue->Text = L"";
            this->columnHeader_imagValue->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
            // 
            // columnHeader_normName
            // 
            this->columnHeader_normName->Text = L"";
            this->columnHeader_normName->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
            // 
            // columnHeader_normValue
            // 
            this->columnHeader_normValue->Text = L"";
            this->columnHeader_normValue->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
            // 
            // button_Fresh
            // 
            this->button_Fresh->Location = System::Drawing::Point(310, 438);
            this->button_Fresh->Name = L"button_Fresh";
            this->button_Fresh->Size = System::Drawing::Size(75, 23);
            this->button_Fresh->TabIndex = 1;
            this->button_Fresh->Text = L"Fresh";
            this->button_Fresh->UseVisualStyleBackColor = true;
            this->button_Fresh->Click += gcnew System::EventHandler(this, &TextGUI::button_Fresh_Click);
            // 
            // TextGUI
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(698, 473);
            this->Controls->Add(this->button_Fresh);
            this->Controls->Add(this->myListview);
            this->Name = L"TextGUI";
            this->Text = L"Text Display";
            this->ResumeLayout(false);

        }
#pragma endregion
    private: System::Void button_Fresh_Click(System::Object^  sender, System::EventArgs^  e) {

                this->myListview->BeginUpdate();
                this->myListview->Clear();

                 int TextNum=8;
                 for(int groupNum=0;groupNum<TextNum;groupNum++)
                 {
                     ListViewGroup^ oneListGroup=addOneGroup(groupNum);
                     addTextItems(groupNum,oneListGroup);
                 }
                this->myListview->EndUpdate();

             }
    private: ListViewGroup^ addOneGroup(int groupNum)
             {
                 ListViewGroup^ ret=nullptr;
                 ListViewGroup^ listViewGroup=(gcnew System::Windows::Forms::ListViewGroup(L"Text"+groupNum.ToString(), HorizontalAlignment::Left));
                 listViewGroup->Name=L"listViewGroup_"+L"Text"+groupNum.ToString();
                 this->myListview->Groups->Add(listViewGroup);               
                 ret=listViewGroup;
                 return ret;
             }
    private: void addTextItems(int groupNum,ListViewGroup^ oneListGroup)
             {
                  addComplexItems(groupNum,oneListGroup);
                  addVarItems(groupNum,oneListGroup);
             }



    private: void addComplexItems(int groupNum,ListViewGroup^ oneListGroup)
             {
                 int complexItemNum=4;
                 for(int complexItemIndex=0;complexItemIndex<complexItemNum;complexItemIndex++)
                 {
                     addOneComplexItem(complexItemIndex,groupNum,oneListGroup);
                 }
             }
   private: void addOneComplexItem(int complexItemNum,int groupNum,ListViewGroup^ oneListGroup)
            {
                ListViewItem^  oneListViewItem = gcnew ListViewItem(oneListGroup);

                String^ realRegisterName=L"XXX_"+groupNum+L"Y_"+getRegisterCombineNum(complexItemNum)+L"_r"; 
                oneListViewItem->Text=realRegisterName;

                String^ realRegisterValue="value";

                oneListViewItem->SubItems->Add(realRegisterValue);

                String^ imagRegisterName=L"XXX_"+groupNum+L"Y_"+getRegisterCombineNum(complexItemNum)+L"_w"; 
                oneListViewItem->SubItems->Add(imagRegisterName);

                String^ imagRegisterValue="value";
                oneListViewItem->SubItems->Add(imagRegisterValue);

                String^ normName=L"ZZZ_("+getRegisterCombineNum(complexItemNum)+L")"; 
                oneListViewItem->SubItems->Add(normName);

                String^ normValue="tt";
                oneListViewItem->SubItems->Add(normValue);
                this->myListview->Items->Add(oneListViewItem);

            }

   private: void addVarItems(int groupNum,ListViewGroup^ oneListGroup)
             {
                 for(int i=1;i<=2;i++)
                 {
                     addOneVarItem(i,groupNum,oneListGroup);
                 }
             }
    private: void addOneVarItem(int index,int groupNum,ListViewGroup^ oneListGroup)
             {
                ListViewItem^  oneListViewItem = gcnew ListViewItem(oneListGroup);

                String^ varRegisterName=L"QQQ_"+groupNum+L"v"+index; 
                oneListViewItem->SubItems->Add(varRegisterName);

                String^ varRegisterValue="ss";
                oneListViewItem->SubItems->Add(varRegisterValue);
                this->myListview->Items->Add(oneListViewItem);
             }
   private:  String^ getRegisterCombineNum(int index)
             {
                 String^ ret="";
                 int vL=1;
                 int vR=1;
                 vL+=index&0x01;
                 vR+=(index>>1)&0x01;
                 return ret +=vL.ToString()+vR.ToString();
             }
};
}

// test.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"

using namespace TextTest;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
    // Enabling Windows XP visual effects before any controls are created
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false); 

    // Create the main window and run it
    Application::Run(gcnew TextGUI());
    return 0;
}