我使用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