2015-01-10 81 views
0

我有下面的方法。在此方法之前,我從一個表中獲取數據,現在從兩個表中獲取數據,因此我更改了ListView,如下所示。ListView不顯示第一列

在使用兩個不同的表之前,ListView是在屬性選項卡中設計的,並且所有工作都很好。

寫入項目時,下面的方法繞過第一列並從第二列開始。

什麼是錯誤?

任何幫助將是非常寶貴的。

private void ShowPage() 
    { 
     // some declarations such count,LineNbr etc... 
     if (PublicVariables.PrintData == 1) 
     { 
      // seeting column headers and with and alignement if PrintData=1 
      newtmp = new string[5]; 
     } 
     else 
     { 
      // seeting column headers and with and alignement if PrintData=2 
      newtmp = new string[7]; 
     } 
     LineNbr = File.ReadAllLines(fName).Length; 
     ppc.View = View.Details; 
     ListViewItem DispItem = new ListViewItem(); 
     while (counter < LineNbr && (line = streamToPrint.ReadLine()) != null) 
     { 
      string[] tmp = line.Split('|');   // Splitting the Data 
      sayac = 0; 
      for (int i = 0; i < tmp.Length; ++i) 
      { 
       if (tmp[i] != "") 
       { 
        newtmp[sayac] = tmp[i]; 
        ++sayac; 
       } 
      } 
      for (int a=0; a<newtmp.Length; ++a)  // I add to SubItems 
       DispItem.SubItems.Add(newtmp[a]);  
      ppc.Items.AddRange(new ListViewItem[] {DispItem}); // I pass to ListView ppc 
      if (PublicVariables.PrintData == 1)   //Initialise newtmp string 
       newtmp = new string[5]; 
      else 
       newtmp = new string[7]; 
      DispItem = new ListViewItem();    // Initialiase ListViewItem 
      ++counter; 
     } 
    } 

回答

1
 for (int a=0; a<newtmp.Length; ++a)  // I add to SubItems 
      DispItem.SubItems.Add(newtmp[a]);  
     ppc.Items.AddRange(new ListViewItem[] {DispItem}); // I pass to Lis 

而是那些線以上,我必須如下:(做

  DispItem = new ListViewItem(newtmp); 
      ppc.Items.Add(DispItem); 

我亂投醫解決這個問題。

畢竟,我就會逃避那些誰記得

+0

這應該是對你的問題的編輯嗎 – theMayer

+0

我在想同樣的事情:),只是在Google上搜索AddRa nge方法,不知道它做了什麼。 – Codeek

+0

@theMayer是的,我找到了解決方案和我所做的錯誤。自從2天以來,這就是在摧毀我 –