Why my ListBox doesn't work??

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

Guest

I setup 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 on the 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.
 
Dear Questions,
A small code snippet goes a long way towards helping others to understand
what is it you are doing wrong
 
////class1.cs
form1.display ( display_message );
////Form1.cs
public void display(string dis_m)
{
MessageBox.Show(dis_m);
listBox.Items.Add("dis_m");
}

/*Message dialog is shown correctly, but the listbox keeps empty, why?*/
 
//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*/
 
Are you sure it's the right listbox? Also, not that it changes anything
significantly, but you have quotes around dis_m in the call to
ListBox.Items.Add
 
Back
Top