2014-03-12 14 views
-1

我有一個列表框,其中包含從某個文件夾加載的一些圖片文件的名稱。當我點擊列表框中的一個項目時,它會被加載到一個圖片框(一種縮略圖)。我有2個按鈕Next/Previous,我想用它來瀏覽列表框和列表框,以根據圖片框中顯示的圖片更新當前選定的文件,但只使用這些按鈕,不必單擊任何項​​目。C#選擇列表框中的下一個項目,而不必點擊它

謝謝!

+0

你嘗試過什麼 – Gun

回答

1

嘗試以下操作:

上(去 '上升'):

private void listPrevious(object sender, System.Windows.RoutedEventArgs e) 
{ 
    if (myListBox.SelectedIndex > 0) 
    { 
     myListBox.SelectedIndex = myListBox.SelectedIndex - 1; 
    } 
} 

下一頁(展望 '向下'):

private void listNext(object sender, System.Windows.RoutedEventArgs e) 
{ 
    if (myListBox.SelectedIndex < myListBox.Items.Count - 1) 
    { 
     myListBox.SelectedIndex = myListBox.SelectedIndex + 1; 
    } 
} 
+0

這工作:)謝謝 – Tzoma

+0

@Tzoma我很高興能幫助你。請標記爲「已回答」,以便其他用戶會看到您不再需要幫助。祝你好運 ! :) – Hyarantar

相關問題