728x90
반응형
실제 데이터 타입은 보통 컴포넌트 타입을 따라가거나 Object 형식으로 되어있음.
- checkedListBox1.CheckedItems : CheckedListBox.CheckedItemCollection
- listBox1.Items : ListBox.ObjectCollection
- listBox1.SelectedItems : ListBox.SelectedObjectCollection
원하는 ObjectCollection을 .OfType<string>().ToArray()를 이용하여
string array로 변경할 수 있다.
1
2
3
4
5
6
7
8
9
10
|
string[] checkBoxCheckedData = checkedListBox1.CheckedItems.OfType<string>().ToArray();
//checkBoxCheckedData[0] = "Red"
//checkBoxCheckedData[1] = "Blue"
string[] listBoxData = listBox1.Items.OfType<string>().ToArray();
//listBoxData[0] = "Black"
//listBoxData[1] = "White"
//listBoxData[2] = "Pink"
//listBoxData[3] = "Purple"
string[] listBoxSelectedData = listBox1.SelectedItems.OfType<string>().ToArray();
//listBoxSelectedData[0] = "Black"
|
cs |
Enumerable.OfType<TResult>(IEnumerable) 메서드 (System.Linq)
지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.
learn.microsoft.com
728x90
반응형
'IT > C#' 카테고리의 다른 글
[C#] ListBox SelectionMode 차이 (None, One, MultiSimple, MultiExtended) (1) | 2024.11.11 |
---|---|
[C#] FlowLayoutPanel TopDown 방향인데 스크롤이 좌우로만 나타나는 현상 (5) | 2024.11.08 |
[C#] Bit, Byte, Word 정리. C# 자료형 사이즈 범위 정리. BitConverter 사용 예시. (1) | 2024.10.03 |
[C#] Enum 값 Array 배열처럼 사용하기. Enum 길이 구하기. (0) | 2024.09.04 |
[C#] 폴더 혹은 파일, Zip 압축 및 추출(압축풀기)하는 방법. Send to Compressed (zipped) folder, Extract All. (2) | 2024.06.13 |