Problem about ListBox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I create a Form and call another class (e.g. class1.cs). (class1.cs) contains
a command to call back the Form to display a string variable in a listbox.
However, it doesn't works. The listbox gets no response.
Command:
listBox.Items.Add( str );
However, it works when i type "MessageBox.Show( str);". A correct string
displays in the popup message box.
Can anyone help me?
 
Hi,

Could you be more precise with:
"(class1.cs) contains a command to call back the Form to display a
string variable in a listbox"

Do you keep form reference in that class or do you raise any event?

Regards

Marcin
 
You will probably need to create a public function in the form that takes
the str as a parameter.
Then you can call the function from (class1.cs)
 
//class1.cs
display ( display_message );
//Form1.cs
public void display(string dis_m)
{
MessageBox.Show(dis_m);
listBox.Items.Add(dis_m);
}

/*Message Dialog display correctly, but the listbox is still empty. Please
help me*/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top