다른 클래스의 목록 상자에 항목을 추가하려고하는데 정보가 함수에 전달되지만 목록 상자가 업데이트되지 않는 것 같습니다.다른 클래스의 목록 상자에 항목을 추가 할 수 없습니다. C#
Main class (FORM) :
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// the function that updates the listbox
public void logURI(string OutputLog, string Information, string JOB)
{
try
{
listBox1.BeginUpdate();
listBox1.Items.Insert(0, DateTime.Now.ToString() + " : " + JOB + " " + Information);
listBox1.Items.Add("1");
listBox1.EndUpdate();
textBox1.Text = JOB;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
두 번째 클래스 :
public class FtpFileSystemWatcherTS
{
Form1 logs = new Form1();
logs.logURI("", "Found folder modefied today (" + FileName.TrimEnd(), ") ElectricaTS");
}
내가 잘못하고있는 중이 이것이 내 코드?
는 두 번째에 대한 좀 더 많은 정보를 제공하십시오 클래스와 폼의 사용법. FtpFileSystemWatcherTS 클래스에서 생성 한 폼을 표시하고 있습니까? 아니면 폼의 인스턴스가 둘 이상입니까? – MatthiasG
textBox1이 업데이트됩니까? Visual Studio 디버거에서 코드를 실행하면 출력 창에 오류 메시지가 표시됩니까? – dgvid
목록 상자에 2 개의 항목 만 추가하기 때문에 BeginUpdate 및 EndUpdate를 호출 할 필요가 없습니다. – evasilchenko