C
C#6mo ago
chronos

listbox display help !

Any idea why this listbox isnt working?
No description
No description
No description
31 Replies
chronos
chronos6mo ago
No description
chronos
chronos6mo ago
when i try to add an item from the list, it just displays this each item is tied to a location instead of the corresponding item it just says blaisefinalproject.item and only allows one to be added
Jimmacle
Jimmacle6mo ago
it is probably simply calling ToString on your object to determine what to display in the list so the quick and dirty fix would be to override ToString for your item to display what you want i would expect there to be a better way but i avoid winforms
chronos
chronos6mo ago
i also do not like winforms this is for a school assignment .. also thanks i’ll try that ❤️ ok@i feel a little silly how would i do that where do i put the .ToString
Jimmacle
Jimmacle6mo ago
you need to override that method in your Item class
chronos
chronos6mo ago
errr
Jimmacle
Jimmacle6mo ago
like
public override string ToString()
{
return ItemName;
}
public override string ToString()
{
return ItemName;
}
chronos
chronos6mo ago
oh yeah silly me i’ve done that before in this project already
chronos
chronos6mo ago
No description
chronos
chronos6mo ago
hmm
Jimmacle
Jimmacle6mo ago
why are you writing that?
chronos
chronos6mo ago
um to convert it to a string.. : P
Jimmacle
Jimmacle6mo ago
you don't need to
chronos
chronos6mo ago
well
Jimmacle
Jimmacle6mo ago
winforms is calling it itself
chronos
chronos6mo ago
it doesn’t work still.. WAIT ok it works kind of now it gets the correct item but i can only store one?
Jimmacle
Jimmacle6mo ago
store one where?
chronos
chronos6mo ago
No description
chronos
chronos6mo ago
when i try to add more items nothing happens
Jimmacle
Jimmacle6mo ago
if you update the list you need to tell winforms it updated somehow
chronos
chronos6mo ago
only the first is registered
Jimmacle
Jimmacle6mo ago
which is where my knowledge of winforms stops
chronos
chronos6mo ago
i shall look this up
Jimmacle
Jimmacle6mo ago
i don't know if winforms has data binding but that's what i'd use in other frameworks
chronos
chronos6mo ago
i think it’s just .Refresh ok nope anyone else know what’s up with this
chronos
chronos6mo ago
No description
chronos
chronos6mo ago
it just displays the first item i get and nothing else
chronos
chronos6mo ago
No description
chronos
chronos6mo ago
my assignment is due soon... i hope help arrives..
chronos
chronos6mo ago
No description
chronos
chronos6mo ago
what does this mean.. nvm IT WORKS solved. got it.