2017-05-08 4 views

答えて

0

両方のリストボックスのすべての項目を選択してそれぞれのリストに挿入すると、Except拡張方法を使用して、最初のリストから2番目のリストから要素を減算することができますリストボックス1の名前はリストボックス2にありません

var listBox1 = ListBox1.Items.Cast<String>().ToList(); 
var listBox2 = ListBox2.Items.Cast<String>().ToList(); 
var resultSet = listBox1.Except(listBox2); 

foreach (var item in resultSet) 
{ 
    // do something 
} 
0

あなたは、各リストボックスで選択した値を取得する必要がまず

If(a ==b) 
{ 
//do nothing 
} 
else 
{ 
//do something 
} 

それとも、常にこのことを試みることができるを比較する場合やelseステートメントを使用し、その後、文字列変数に渡します道

If(a != b) 
{ 
//do something 
} 
0

listbox1を上の項目はListbox2にない場合は、比較するために、foreachループを行うことができます。

foreach (var item in listBox1.Items) 
     { 
      if (!listBox2.Items.Contains(item)) 
      { 
       //TODO: Do your logic here 
      } 
     } 
0

答えるために:

チェックをlistbox1をに記載されている任意の名前がlistbox2か

foreach (var list1Item in listBox1.Items) 
    foreach(var list2Item in lisBox2.Items) 
     if (list1Item == list2Item) 
     { 
      // Identical items found. Handle with your code 
     } 

とTOに記載されていた場合:がある場合

listbox1の中のlistbox2にない名前、次にperforアクションです。これを行う方法?

foreach (string item in listBox1.Items) 
     if(!listBox2.Items.Contains(item)) 
     { 
      // 'item' is present in listBox1, not in listBox2. Handle yourself. 
     } 
関連する問題