2017-05-12 20 views
2

だから、私のリストビューはアイテムでいっぱいです。アイテムを選択すると、最初の行は正常に動作しますが、次の行が次の行を表示します。リスト表示選択したアイテムをテキストボックス

はだから1 = C1 TextBox1テキストボックスは= C2

行2の2行目の値を示しているTextBox1テキストボックスは、行の最初の行の値に示す

列1-4 C1、C2、C3、C4のようになります

私はそれをC1にとどめる必要があるとき

編集: だから、各行See Photoのプロパティを読んでジョブファイルに行きたいと思っています。しかし、問題はジョブファイルがプロパティフォルダを持っているので、各行から取得した値を適切なフォルダに移動して意味がある場合は、そのフォルダに移動します。しかし、どのように動作するはずです写真では、私はその1つの下の行を選択するとintが存在しないため、私にエラーが発生します。後続の各行は、間違ったテキストボックスにその横の列の値を入れたいからです。

エラー:System.ArgumentOutOfRangeException: 'InvalidArgument =' 1 'の値が' index 'に無効です。'

private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) 
    { 

     int Itemindex = e.ItemIndex; 
     ListViewItem item = listView1.SelectedItems[Itemindex]; 
     //fill the text boxes 
     textBox2.Text = item.Text; 
     textBox3.Text = item.SubItems[1].Text; 
     textBox4.Text = item.SubItems[2].Text; 
     textBox5.Text = item.SubItems[3].Text; 

    } 

private void Chad2017() 
    { 
     try 
     { 
      if (textBox1.Text != "arc1") 
      { 
       textBox1.Text = "arc1"; 
       listView1.Visible = true; 


       listView1.Sort(); 
       string[] dirs = Directory.GetDirectories(JobArc1 + @"\2017\1-January"); 
       string[] dirs1 = Directory.GetDirectories(JobArc1 + @"\2017\2-February"); 
       string[] dirs2 = Directory.GetDirectories(JobArc1 + @"\2017\3-March"); 
       string[] dirs3 = Directory.GetDirectories(JobArc1 + @"\2017\4-April"); 
       string[] dirs4 = Directory.GetDirectories(JobArc1 + @"\2017\5-May"); 
       string[] dirs5 = Directory.GetDirectories(JobArc1 + @"\2017\6-June"); 
       string[] dirs6 = Directory.GetDirectories(JobArc1 + @"\2017\7-July"); 
       string[] dirs7 = Directory.GetDirectories(JobArc1 + @"\2017\8-August"); 
       string[] dirs8 = Directory.GetDirectories(JobArc1 + @"\2017\9-September"); 
       string[] dirs9 = Directory.GetDirectories(JobArc1 + @"\2017\10-October"); 
       string[] dirs10 = Directory.GetDirectories(JobArc1 + @"\2017\11-November"); 
       string[] dirs11 = Directory.GetDirectories(JobArc1 + @"\2017\12-December"); 
       string[] files = Directory.GetFiles(JobLoc1); 
       foreach (string dir in dirs) 
       { 
        try 
        { 
         string JobNumber = File.ReadAllText(@dir + "\\Properties\\thisJobNumber.txt"); 
         string JobName = File.ReadAllText(@dir + "\\Properties\\JobName.txt"); 
         string BidDate = File.ReadAllText(@dir + "\\Properties\\BidDate.txt"); 
         string Location = File.ReadAllText(@dir + "\\Properties\\Location.txt"); 
         string Contact = File.ReadAllText(@dir + "\\Properties\\Contact.txt"); 
         string[] JobInfo = { JobName, BidDate, Location, Contact }; 

         ListViewItem item1 = new ListViewItem(); 

         if (Contact != "") 
         { 
          listView1.Items.Add(JobNumber).SubItems.AddRange(JobInfo); 
          // listView1.Items[].SubItems.Add(File.ReadAllText(@dir + "\\Properties\\JobName.txt")); 
         } 
        } 
        catch { } 
       } 
       foreach (string dir1 in dirs1) 
       { 
        try 
        { 
         string JobNumber = File.ReadAllText(@dir1 + "\\Properties\\thisJobNumber.txt"); 
         string JobName = File.ReadAllText(@dir1 + "\\Properties\\JobName.txt"); 
         string BidDate = File.ReadAllText(@dir1 + "\\Properties\\BidDate.txt"); 
         string Location = File.ReadAllText(@dir1 + "\\Properties\\Location.txt"); 
         string Contact = File.ReadAllText(@dir1 + "\\Properties\\Contact.txt"); 
         string[] JobInfo = { JobName, BidDate, Location, Contact }; 

         ListViewItem item1 = new ListViewItem(); 

         if (Contact != "") 
         { 
          listView1.Items.Add(JobNumber).SubItems.AddRange(JobInfo); 
          // listView1.Items[].SubItems.Add(File.ReadAllText(@dir + "\\Properties\\JobName.txt")); 
         } 
        } 
        catch { } 
       } 

       for each (string dir2 in dirs2) 
       { 
        try 
        { 
         string JobNumber = File.ReadAllText(@dir2 + "\\Properties\\thisJobNumber.txt"); 
         string JobName = File.ReadAllText(@dir2 + "\\Properties\\JobName.txt"); 
         string BidDate = File.ReadAllText(@dir2 + "\\Properties\\BidDate.txt"); 
         string Location = File.ReadAllText(@dir2 + "\\Properties\\Location.txt"); 
         string Contact = File.ReadAllText(@dir2 + "\\Properties\\Contact.txt"); 
         string[] JobInfo = { JobName, BidDate, Location, Contact }; 

         ListViewItem item1 = new ListViewItem(); 

         if (Contact != "") 
         { 
          listView1.Items.Add(JobNumber).SubItems.AddRange(JobInfo); 
          // listView1.Items[].SubItems.Add(File.ReadAllText(@dir + "\\Properties\\JobName.txt")); 
         } 
        } 
        catch { } 
       } 
       foreach (string dir3 in dirs3) 
       { 
        try 
        { 
         string JobNumber = File.ReadAllText(@dir3 + "\\Properties\\thisJobNumber.txt"); 
         string JobName = File.ReadAllText(@dir3 + "\\Properties\\JobName.txt"); 
         string BidDate = File.ReadAllText(@dir3 + "\\Properties\\BidDate.txt"); 
         string Location = File.ReadAllText(@dir3 + "\\Properties\\Location.txt"); 
         string Contact = File.ReadAllText(@dir3 + "\\Properties\\Contact.txt"); 
         string[] JobInfo = { JobName, BidDate, Location, Contact }; 

         ListViewItem item1 = new ListViewItem(); 

         if (Contact != "") 
         { 
          listView1.Items.Add(JobNumber).SubItems.AddRange(JobInfo); 
          // listView1.Items[].SubItems.Add(File.ReadAllText(@dir + "\\Properties\\JobName.txt")); 
         } 
        } 
        catch { } 
       } 
       foreach (string dir4 in dirs4) 
       { 
        try 
        { 
         string JobNumber = File.ReadAllText(@dir4 + "\\Properties\\thisJobNumber.txt"); 
         string JobName = File.ReadAllText(@dir4 + "\\Properties\\JobName.txt"); 
         string BidDate = File.ReadAllText(@dir4 + "\\Properties\\BidDate.txt"); 
         string Location = File.ReadAllText(@dir4 + "\\Properties\\Location.txt"); 
         string Contact = File.ReadAllText(@dir4 + "\\Properties\\Contact.txt"); 
         string[] JobInfo = { JobName, BidDate, Location, Contact }; 

         ListViewItem item1 = new ListViewItem(); 

         if (Contact != "") 
         { 
          listView1.Items.Add(JobNumber).SubItems.AddRange(JobInfo); 
          // listView1.Items[].SubItems.Add(File.ReadAllText(@dir + "\\Properties\\JobName.txt")); 
         } 
        } 
        catch { } 
       } 
       foreach (string dir5 in dirs5) 
       { 
        try 
        { 
         string JobNumber = File.ReadAllText(@dir5 + "\\Properties\\thisJobNumber.txt"); 
         string JobName = File.ReadAllText(@dir5 + "\\Properties\\JobName.txt"); 
         string BidDate = File.ReadAllText(@dir5 + "\\Properties\\BidDate.txt"); 
         string Location = File.ReadAllText(@dir5 + "\\Properties\\Location.txt"); 
         string Contact = File.ReadAllText(@dir5 + "\\Properties\\Contact.txt"); 
         string[] JobInfo = { JobName, BidDate, Location, Contact }; 

         ListViewItem item1 = new ListViewItem(); 

         if (Contact != "") 
         { 
          listView1.Items.Add(JobNumber).SubItems.AddRange(JobInfo); 
          // listView1.Items[].SubItems.Add(File.ReadAllText(@dir + "\\Properties\\JobName.txt")); 
         } 
        } 
        catch { } 
       } 
       foreach (string dir6 in dirs6) 
       { 
        try 
        { 
         string JobNumber = File.ReadAllText(@dir6 + "\\Properties\\thisJobNumber.txt"); 
         string JobName = File.ReadAllText(@dir6 + "\\Properties\\JobName.txt"); 
         string BidDate = File.ReadAllText(@dir6 + "\\Properties\\BidDate.txt"); 
         string Location = File.ReadAllText(@dir6 + "\\Properties\\Location.txt"); 
         string Contact = File.ReadAllText(@dir6 + "\\Properties\\Contact.txt"); 
         string[] JobInfo = { JobName, BidDate, Location, Contact }; 

         ListViewItem item1 = new ListViewItem(); 

         if (Contact != "") 
         { 
          listView1.Items.Add(JobNumber).SubItems.AddRange(JobInfo); 
          // listView1.Items[].SubItems.Add(File.ReadAllText(@dir + "\\Properties\\JobName.txt")); 
         } 
        } 
        catch { } 
       } 
       foreach (string dir7 in dirs7) 
       { 
        try 
        { 
         string JobNumber = File.ReadAllText(@dir7 + "\\Properties\\thisJobNumber.txt"); 
         string JobName = File.ReadAllText(@dir7 + "\\Properties\\JobName.txt"); 
         string BidDate = File.ReadAllText(@dir7 + "\\Properties\\BidDate.txt"); 
         string Location = File.ReadAllText(@dir7 + "\\Properties\\Location.txt"); 
         string Contact = File.ReadAllText(@dir7 + "\\Properties\\Contact.txt"); 
         string[] JobInfo = { JobName, BidDate, Location, Contact }; 

         ListViewItem item1 = new ListViewItem(); 

         if (Contact != "") 
         { 
          listView1.Items.Add(JobNumber).SubItems.AddRange(JobInfo); 
          // listView1.Items[].SubItems.Add(File.ReadAllText(@dir + "\\Properties\\JobName.txt")); 
         } 
        } 
        catch { } 


       } 
       foreach (string dir8 in dirs8) 
       { 
        try 
        { 
         string JobNumber = File.ReadAllText(@dir8 + "\\Properties\\thisJobNumber.txt"); 
         string JobName = File.ReadAllText(@dir8 + "\\Properties\\JobName.txt"); 
         string BidDate = File.ReadAllText(@dir8 + "\\Properties\\BidDate.txt"); 
         string Location = File.ReadAllText(@dir8 + "\\Properties\\Location.txt"); 
         string Contact = File.ReadAllText(@dir8 + "\\Properties\\Contact.txt"); 
         string[] JobInfo = { JobName, BidDate, Location, Contact }; 

         ListViewItem item1 = new ListViewItem(); 

         if (Contact != "") 
         { 
          listView1.Items.Add(JobNumber).SubItems.AddRange(JobInfo); 
          // listView1.Items[].SubItems.Add(File.ReadAllText(@dir + "\\Properties\\JobName.txt")); 
         } 
        } 
        catch { } 
       } 
       foreach (string dir9 in dirs9) 
       { 
        try 
        { 
         string JobNumber = File.ReadAllText(@dir9 + "\\Properties\\thisJobNumber.txt"); 
         string JobName = File.ReadAllText(@dir9 + "\\Properties\\JobName.txt"); 
         string BidDate = File.ReadAllText(@dir9 + "\\Properties\\BidDate.txt"); 
         string Location = File.ReadAllText(@dir9 + "\\Properties\\Location.txt"); 
         string Contact = File.ReadAllText(@dir9 + "\\Properties\\Contact.txt"); 
         string[] JobInfo = { JobName, BidDate, Location, Contact }; 

         ListViewItem item1 = new ListViewItem(); 

         if (Contact != "") 
         { 
          listView1.Items.Add(JobNumber).SubItems.AddRange(JobInfo); 
          // listView1.Items[].SubItems.Add(File.ReadAllText(@dir + "\\Properties\\JobName.txt")); 
         } 
        } 
        catch { } 
       } 
       foreach (string dir10 in dirs10) 
       { 
        try 
        { 
         string JobNumber = File.ReadAllText(@dir10 + "\\Properties\\thisJobNumber.txt"); 
         string JobName = File.ReadAllText(@dir10 + "\\Properties\\JobName.txt"); 
         string BidDate = File.ReadAllText(@dir10 + "\\Properties\\BidDate.txt"); 
         string Location = File.ReadAllText(@dir10 + "\\Properties\\Location.txt"); 
         string Contact = File.ReadAllText(@dir10 + "\\Properties\\Contact.txt"); 
         string[] JobInfo = { JobName, BidDate, Location, Contact }; 

         ListViewItem item1 = new ListViewItem(); 

         if (Contact != "") 
         { 
          listView1.Items.Add(JobNumber).SubItems.AddRange(JobInfo); 
          // listView1.Items[].SubItems.Add(File.ReadAllText(@dir + "\\Properties\\JobName.txt")); 
         } 
        } 
        catch { } 
       } 
       foreach (string dir11 in dirs11) 
       { 
        try 
        { 
         string JobNumber = File.ReadAllText(@dir11 + "\\Properties\\thisJobNumber.txt"); 
         string JobName = File.ReadAllText(@dir11 + "\\Properties\\JobName.txt"); 
         string BidDate = File.ReadAllText(@dir11 + "\\Properties\\BidDate.txt"); 
         string Location = File.ReadAllText(@dir11 + "\\Properties\\Location.txt"); 
         string Contact = File.ReadAllText(@dir11 + "\\Properties\\Contact.txt"); 
         string[] JobInfo = { JobName, BidDate, Location, Contact }; 

         ListViewItem item1 = new ListViewItem(); 

         if (Contact != "") 
         { 
          listView1.Items.Add(JobNumber).SubItems.AddRange(JobInfo); 
          // listView1.Items[].SubItems.Add(File.ReadAllText(@dir + "\\Properties\\JobName.txt")); 
         } 
        } 
        catch { } 
       } 
      } 
      else 
      { 
       textBox1.Text = "arc0"; 
       listView1.Visible = false; 
      } 

     } 
     catch { } 
    } 
private void button1_Click(object sender, EventArgs e) 
    { 

     try 
     { 

      if (textBox1.Text != "1") 
      { 
       textBox1.Text = "1"; 
       listView1.Visible = true; 
       listView1.Items.Clear(); 

       listView1.Sort(); 
       string[] dirs = Directory.GetDirectories(JobLoc1); 
       string[] files = Directory.GetFiles(JobLoc1); 
       foreach (string dir in dirs) 
       { 
        try 
        { 
         string JobNumber = File.ReadAllText(@dir + "\\Properties\\thisJobNumber.txt"); 
         string JobName = File.ReadAllText(@dir + "\\Properties\\JobName.txt"); 
         string BidDate = File.ReadAllText(@dir + "\\Properties\\BidDate.txt"); 
         string Location = File.ReadAllText(@dir + "\\Properties\\Location.txt"); 
         string Contact = File.ReadAllText(@dir + "\\Properties\\Contact.txt"); 
         string[] JobInfo = { JobName, BidDate, Location, Contact }; 

         ListViewItem item1 = new ListViewItem(); 

         if (JobNumber != "") 
         { 
          listView1.Items.Add(JobNumber).SubItems.AddRange(JobInfo); 
          // listView1.Items[].SubItems.Add(File.ReadAllText(@dir + "\\Properties\\JobName.txt")); 
         } 
        } 
        catch { } 
       } 
      } 

      else 
      { 
       textBox1.Text = "0"; 
       listView1.Visible = false; 
      } 
+0

ありません。あなたはどんなエラーを出していますか?イベントが実行されているコードブロック全体を送信します。 – LarsTech

+0

これであまりにも多くのコードを追加しました。どの行がエラーをスローしますか?空のtry-catchを使用しないでください。デバッガを使用してオブジェクトを検査します。あなたはまだ*最初のコードブロックを使用している*表示していません。 – LarsTech

+0

LarsTechどのような行にエラーが表示されているかを更新しました –

答えて

0

SelectedItemsはItemsコレクションとは異なるコレクションです。

変更この:これに

int Itemindex = e.ItemIndex; 
ListViewItem item = listView1.SelectedItems[Itemindex]; 

:十分に明確

int Itemindex = e.ItemIndex; 
ListViewItem item = listView1.Items[Itemindex]; 
+0

すみません、申し訳ありません。 –

関連する問題