我的CListCtrl空间采用Report模式,有3列,N行,有个很奇怪的问题,插入3行以上数据才能正常显示,插入第一行时只能显示第一列,插入第2行时只能显示前2列,插入第3行以后就全正常了,咋也找不到问题,很奇怪,请高手指教,就是说插入3行以上就全部显示正常

解决方案 »

  1.   

    TCHAR rgtsz[3][15] = {_T("状态ID"),_T("状态名称"),_T("说明")};

    LV_COLUMN lvcolumn;

    // Insert columns using the order field
    for(int i = 0; i <3; i++)  
    {
    lvcolumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH | LVCF_ORDER;
    lvcolumn.fmt = LVCFMT_CENTER;
    lvcolumn.pszText = rgtsz[i];
    lvcolumn.iSubItem = i;
    lvcolumn.iOrder = i;
    if(i == 0)
    lvcolumn.cx = 100;
    else if(i == 1)
    lvcolumn.cx = 100;
    else if(i == 2)
    lvcolumn.cx = 380;

    m_ReportList.InsertColumn(i, &lvcolumn);  
    m_ReportList.Invalidate();
      

  2.   

    你把m_ReportList.Invalidate();放到for循环外会怎样?
    你的代码的意思好像就是每插入一个,跟新一下
      

  3.   

    我用你的代码试了一下,能行啊。就是弄一个List控件,给他一个空间类型的变量m_ReportList,然后在初始化里复制了你的代码,能初始化啊
      

  4.   

    跟这个有关系吗??我把m_ReportList.Invalidate()去掉或是不管放哪里都不行,最怪的就是显示3行以上就正常了,太奇怪了
      

  5.   

    我加了一个按钮,代码是:m_ReportList.InsertItem(0, "11111111");
    m_ReportList.SetItemText(0, 1, "22222222");
    m_ReportList.SetItemText(0, 2, "3333333");
    UpdateData(FALSE);没啥问题
      

  6.   

    BOOL CXxxDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon//////////////////这个地方往下是复制你的,其他的都是自动生成的
    // TODO: Add extra initialization here
    TCHAR rgtsz[3][15] = {_T("状态ID"),_T("状态名称"),_T("说明")};LV_COLUMN lvcolumn;// Insert columns using the order field
    for(int i = 0; i <3; i++)  
    {
    lvcolumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH | LVCF_ORDER;
    lvcolumn.fmt = LVCFMT_CENTER;
    lvcolumn.pszText = rgtsz[i];
    lvcolumn.iSubItem = i;
    lvcolumn.iOrder = i;
    if(i == 0)
    lvcolumn.cx = 100;
    else if(i == 1)
    lvcolumn.cx = 100;
    else if(i == 2)
    lvcolumn.cx = 380; m_ReportList.InsertColumn(i, &lvcolumn);  
    // m_ReportList.Invalidate();
    }

    //////////////////这个地方往上是复制你的,其他的都是自动生成的 return TRUE;  // return TRUE  unless you set the focus to a control
    }
      

  7.   

    这个是按钮代码:void CXxxDlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    m_ReportList.InsertItem(0, "xxxxxxxxxxx");
    m_ReportList.SetItemText(0, 1, "xxxxxxxx");
    m_ReportList.SetItemText(0, 2, "wwwwwwwwww"); UpdateData(FALSE);
    }