β Error with Displaying txt file in a Listbox
Hello, I am having some issues getting a text file to display it's contents in a generated display. Apparently when I run the debugger, it ends up displaying the contents in a seperate page with an additional txt extension attached to it. Can someone tell me what the problem is here?
https://paste.mod.gg/qdpmcphcwgrr/0
BlazeBin - qdpmcphcwgrr
A tool for sharing your source code with the world!
42 Replies
can u maybe post a screenshot of what happens
Ok sure
from the code alone is being hard to figure out what hte actual issue is
This is what I am getting, it's supposed to display in the listbox
Should I send the UI of my application as well?
Here it is in case you need it to understand what is going on
@Gamer1234556 I suspect your try and catch clause if bubbling it try removing it
commenting it
What do I replace it with?
nothing just comment the try and catch
Yeah it seems like there are no changes
super weird behavior then, can you show me your winform code
the designer
why did u have a try and catch there in first place?
BlazeBin - hkzfirtbjmop
A tool for sharing your source code with the world!
It worked before when I originally had a read-only text box. It was to check whether or not the dragged file was a txt file
ah I see the issue
GenerateValueDisplay is a ListBox not a textbox
so GenerateValueDisplay.Items.Add(fileContent)
and that wont play very nicely, since your "items" is just a single long string
a listbox is for many items, not a single one
yep it wouldn't unless he processes it first to split by ,
and add the array
which would make more sense since he wants to sort it in different ways
yup
we've had that exact problem before with the
int.Parse
, remember? πme?
no, Gamer
Yeah
:catlaugh:
I have been posting here for a while
Pobiega has been a great help for me
so if u do the change above does it work?
Well it works but it displays as one item
So that's wrong
yes it is
but it works so u know what to do now right?
I think so...
Do you have any pointers as for getting it to display as multiple items instead of one?
read from there π
what happens when u do that to a string what u get in result?
Yeah it's supposed to be an array
yep which are multiple items π
and if u add 1 by 1 to the list box what happens?
Hold on, I am overhauling the code to get the functionality to work
tyt
Ok, so here is what I have now, but apparently it just skips over whatever items whenever it tries to parse through the text.
before using line I recommend u to check if its not null or empty
on the Split method might also be worth adding to it the parameter to exclude empty elements after
','
if u put a ,
it will give u the option to add a StringSplitOptions enum
aside from that you're not adding anyting to the listbox
a few things on the file u linked:
you dont need to check if filepath is null File.Exists will fail for both so u can just use File.Exists there
fileContent you dont need to check either
if its empty your loop will be skiped
U dont want to call GenerateValueDisplay.Items.AddRange(fileContent);
u want to do that after you processed the files on your resulting array
what happens if line is empty or null there?
it would crash on the line.split
so you want to check line before u use it on the split to ensure its not empty, if its empty just continue to the next line
then
this is where u were suppose to fill your list but instead you're filling something elseOk, I managed to get the DisplayFileContents() working. I needed to make a complete overhaul of the function since textboxes and listboxes are very different and now it is working. The problem now is the sorting algorithms aren't working since the array doesn't seem to exist. You want me to link the code?
sure
BlazeBin - vroztmsfisel
A tool for sharing your source code with the world!
doesn't
GenerateValueDisplay.Items
gives u a string array u can use to sort?
u would take a copy of it work with it then update the listbox again
ah I see it have its own object so
you would have to create a field to store your array aside from feeding your listbox
and if u modify your field u would update your list box with it
alternatively you could cast the listbox item to your type into an array but if this is a homework it probably wont be accepted
this assumes your time was originally of type string in your listbox
if it was not it would fail
you also have to fix all your methods using .TextWell I changed DisplayFileContents() to return a list
But now I might have to change some of the code to accomodate this
BlazeBin - fnsphmbcrfiu
A tool for sharing your source code with the world!
What are some changes to be made here?
SortedValueDisplay.Text
I suppose
but I guess now u should try and see what is not working and if u can fix your self without me telling u
and if u can't then ask us ;P
Ok
Yeah I fixed up code and itβs working properly
Thanks for the help
This place has been a ton of help for me