我使用dosnt的API響應Form_Load事件。所以我想用包含在我用來調用包含CheckedlistBox1的對話框的按鈕中的代碼填充CheckedListBox1。這是我第一次嘗試。從前一個對話框填充CheckedBoxList1
private void button3_Click(object sender, EventArgs e)
{
TextSelectorForm textSelectionForm = new TextSelectorForm();
CheckedListBox checkedListBox1;
string line;
StreamReader file = new StreamReader("test.txt");
while ((line = file.ReadLine()) != null)
{
TextSelectorForm.checkedListBox1.Items.Add(line);
}
file.Close();
textSelectionForm.Show();
}
想法,想法,例子?謝謝!
我收到錯誤「對象引用未設置爲對象的實例」。我在慢慢學習。這是我的代碼。
public partial class Form1 : System.Windows.Forms.Form
{
public Form1(ExternalCommandData commandData)
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
CheckedListBox.ObjectCollection data = null;
string line;
StreamReader file = new StreamReader(@"C:\test.txt");
while ((line = file.ReadLine()) != null)
{
data.Add(line);
}
file.Close();
Form2 form2 = new Form2(data);
form2.Show();
}
}
public partial class Form2 : System.Windows.Forms.Form
{
public Form2(CheckedListBox.ObjectCollection formdata)
{
InitializeComponent();
if (formdata != null)
{
this.checkedListBox1.Items.AddRange(formdata);
}
}
}
(PS。如果我想要添加到我的問題?)
我收到錯誤「Object reference not set to a instance of a object」。我在慢慢學習。這是我的代碼。 – topofsteel 2012-04-24 15:37:49
非常感謝你! – topofsteel 2012-04-24 19:06:24