Thanks for the reply. That worked fine. I did exactly what you both said:
Is the list item really a complexNumber object or a string object now?
If its a string object I need to parse it back to a complex number if I want
to reuse the number. If its a complexnumber object I should be able to just
use select the item and use it again to do calculations. e. g. like this
complexNumber = this.memoryListBox.SelectedItem;
this line gives me an error cannot implicitly convert type object. How would
I get that item back to a variable of my complex type?
public override string ToString()
{
if(Imag > 0)
return string.Format( "{0:F2} + j{1:F2}", Real, Imag);
else
{
double Imag2;
Imag2 = Math.Abs(Imag);
return string.Format("{0:F2} - j{1:F2}", Real, Imag2);
}
}
Is the list item really a complex number object or a string object now?
"Nicholas Paldino [.NET/C# MVP]" wrote:
orahm,
You can override your ToString method on your Complex class type to
return the string representation that you wish to see. The ListBox calls
ToString on the items that are added to it for the display value of the
item.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"orahm" <or***@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...I added an object to a listbox. This object is a complex number and not a
string so it shows "Consolapplication.Complex" as a list item. If I
convert
the complex number to a string then it shows a string which is correct but
also store's it in the listbox as a string. I wan't to store it as a
complex
number but view it as a string. How do I go about doing that?