什麼是檢查是否在CheckedListBox
中檢查了任何內容的代碼。我正在申請註冊電影,我需要檢查從CheckedListBox
電影的流派。如果沒有任何檢查,MessageBox
應該會出現告訴你你需要爲電影選擇一個流派。檢查CheckedListBox?
0
A
回答
1
您應該檢查CheckedItems
或CheckedIndices
性質,這取決於你所需要的
CheckedListBox cl = new CheckedListBox();
if (cl.CheckedIndices.Count == 0)
{
MessageBox.Show("You need to select a Genre for the movie.");
}
0
if(checkedListBox1.CheckedItems.Count != 0)
{
// If so, loop through all checked items and print results.
}
else
{
MessageBox.Show("You need to select a Genre for the movie.");
}
1
你可以簡單地使用SelectedIndex
屬性:
if(checkListBoxGenre.SelectedIndex == -1)
{
MessageBox.Show("You need to select a Genre for the movie.");
}
另一種選擇是使用Text
property它獲取ListBox中當前選定項目的文本。
if(checkListBoxGenre.Text.Length == 0)
{
MessageBox.Show("You need to select a Genre for the movie.");
}
這只是一個可讀性和個人喜好的問題。
相關問題
- 1. 檢查CheckedListBox是否爲空
- 2. CheckedListBox不檢查項目選擇
- 3. 如何遍歷checkedlistbox並檢查項目?
- 4. CheckedListBox只允許檢查一個項目
- 5. Winforms checkedlistbox檢查一個項目
- 6. checkedlistbox項目檢查到列表框
- 7. CheckedListBox檢查項目對象轉換?
- 8. checkedListBox和SQL查詢
- 9. 查詢CheckedListBox正在返回未檢查的元素
- 10. C# - 在檢查特定項目時自動檢查checkedlistbox中的項目
- 11. 如何獲取CheckedListBox檢查項目的ValueMembers?
- 12. 在Checkedlistbox中獲取每個檢查的項目
- 13. Visual Studio 2012 C#:刪除CheckedListBox中的所有*檢查項目
- 14. 如何檢查checkedlistbox中只有一個項目
- 15. 附加檢查項CheckedListBox到difrent在SQL vb.net領域
- 16. 迭代通過checkedListBox測試檢查鑄造錯誤
- 17. CheckedListBox並與它們的索引檢查項目列表
- 18. 如何從CheckedListBox中獲取當前選定的檢查值?
- 19. 檢查項目後,哪個CheckedListBox事件觸發?
- 20. CheckedListBox搜索功能沒有正確檢查
- 21. 當我使用DragDrop時,如何檢查CheckedListBox中的項目
- 22. Powershell CheckedListBox檢查是否在字符串/數組
- 23. 灌裝與檢查的項目列表中CheckedListBox
- 24. 如何從CheckedListBox中獲取檢查項目的值?
- 25. 如何在checkedlistbox中獲取當前已檢查的項目
- 26. Windows C#CheckedListBox檢查項目事件處理
- 27. 阻止從vb.net中的多個checkedlistbox檢查相同的項目
- 28. 上運行CheckedListBox和文件中檢查什麼
- 29. 設置checkedListBox項檢查是否valuemember =東西
- 30. 設置checkedlistbox值檢查不能正常工作
我是這樣做的: else if(GenreCheck.Text.Length == 0) { MessageBox.Show(「請選擇電影的流派。」); } 它工作xD – user1957558
@ user1957558:'Text'屬性返回第一個選定項目的文本。但是如果我想知道是否選擇了某個東西,我會使用'SelectedIndex'。這只是一個可讀性和個人喜好的問題。但編輯我的答案要考慮到這一點。 –
@ user1957558檢查文字不好。更好地檢查我的答案中的兩個屬性中的一個 – VladL