그런 어리석은 질문에 대해 용서해주십시오. 나는 많은 사람들이 이것을 쉽게 찾을 것이라고 확신합니다. 여기서 나는 이것을 거의 알아 내려고 독서의 하루 반 정도를 보냈습니다. 나는 FORM (Form1.cs를) 만든이다른 기능의 C# ListView
- : 여기 문제입니다. 그 형식으로 나는 listview를 만들고 그것을 "ListView1"이라고 명명했다.
- Form1.cs 내에서 FileManager (this)라는 함수를 호출합니다.이 함수는 THIS 개체를 전달합니다.
- FileManager.cs에서 나는 listviewArray = originalForm.Controls.Find ("listView1", true)와 'listview'를 찾을 수있었습니다.
- listviewArray [0] < 할 때 목록을 추가 할 수 없습니다. 컬렉션이 비어 있기 때문에
FileManager.cs
FileManager(object sender)
{
if (sender != null)
{
originalForm = (Form)sender;
}
}
public void getFiles()
{
filePaths = Directory.GetFiles(hsocDir);
if(filePaths != null)
{
listviewArray= originalForm.Controls.Find("listView1", true);
if(listviewArray != null)
{
ListViewItem lvi = new ListViewItem("text");
// My Array is listViewArray
// How to add things to Lvi to it.
}
}
== Form1.cs
public Form1()
{
InitializeComponent(`enter code here`);
mysql = new MySQLCheck(this);
fileManager = new FileManager(this);
fileManager.getFiles();
}
질문 1 : 나는 listView1을 찾기 위해 사용하는 방법이 물건을 추가하려고 올바른 경로를 반대인가? – FlyingV
@ user3443386 그게 아주 합리적인 방법입니다. 심지어 직접 UI 조작을 버리고 MVVM 구현 (WPF 가능성이 있음)을 사용하는 것이 좋습니다. 즉, 프로젝트를 다시 작성할 준비가되지 않았으므로 괜찮습니다. – BradleyDotNET