簡體   English   中英

反轉c#.net中兩個下拉列表中的選定項目

[英]Reverse selected items in two drop down lists in c# .net

我設計了帶有兩個下拉列表的Windows窗體應用程序。

每個刪除列表包含四個硬編碼的項目。

單擊一個按鈕時,它應反轉所選項目。 我想到了使用if條件得出解決方案。 但是,任何簡短的代碼都會有所幫助。

謝謝

單擊該按鈕后,您可以重新分配兩個下拉菜單的數據源:

 // create new list of items in order to not lose them when clearin
 var oldSource = comboBox1.Items.ToList();

 // clear old items to make them not reappear
 comboBox1.Items.Clear();

 // reverse items
 var reversedSource = oldSource.Reverse();

 // iterating over the reversedItems and adding all items
 foreach(var item in reversedSource)
 {
   comboBox1.Items.Add(item);
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM