Displaying text file in listbox c#


















Connect and share knowledge within a single location that is structured and easy to search. I have a list that contains custom objects. I want to create a list of them in a listbox, but the listbox displays only. Is it possible to make the listbox display a certain value for each item? Lets say my objects have an ID string value. Can I display the ID for each item without discarding my objects' other properties? Set the DisplayMember to the property of your class that you'd like the user to see.

Set the DisplayMember to the propertie of your MyClass which you would like to display. Set the items using the DataSource propertie of your ListBox.

You can simple override the ToString method of your MyClass object and return the text you would like to display. How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? How to solve that?? No, the above code which i have written is for 1st listbox event raised only. Not for any other listbox.

An unhandled exception of type 'System. InvalidOperationException' occurred in System. You didn't say which line caused the error, but my guess is that it is caused by the below line. Because the index that you looking for in the file doesn't exist. SelectedIndex and if you have that same index in the.

Yes correct sir, save profile button is for saving the profile list in the file. Also, the 1st listbox saves the list of all profiles created and the 3rd listbox is storing items or moved items from 2nd listbox to 3rd listbox. Another option Which I don't prefer is that you have to check if index selected if it is greater than the lines count, because the error is raised on the last item selected, which is newly added.

The problem is that you are insisting on implementing non-logic behaviour in your code and when am trying to direct in the right way you keep saying I want this way.

The whole event code you sent above doesn't make any sense for example this code below:. You just putting code and trying to make it work. Take a step back and set everything on paper work and make it more logic then come back to, otherwise this is not programming. If you created a new profile then from where it gets the new projects for that profile? That's the non-logic that am talking about.

Not always want to read the last profile saved but lets say for example at 1st time we created 2 profiles and able to display projects associated with it in 3rd listbox. Now, I close the form and later on add 3rd profile item to the 1st listbox and add projects to it and save the profile.

Again just close the form. But i am unable to establish it. And if you want to associate with other projects profile then the must select the other profile and delete the else section below in the above code, because this is clearing the projects if the index not found:. I'm assuming that this profile is new, which means its projects are unknown and needs to be entered by the user. Otherwise where do we get the projects of this new profile from? In the code above, for the 1st listbox event i have written code like this which is mentioned above also This code will move items from 2nd listbox to 3rd listbox for newly created profile.

But, this will not be working when we add new profile once the form is closed and opened again. The content you requested has been removed. Ask a question. Quick access. Search related threads. Remove From My Forums. Asked by:. Archived Forums. Windows Forms Data Controls and Databinding.

The coordinates are saved in a text file with the name of the image. I want to be able to select the image in a listbox and check if there is a text file with the same name as the selected image and then display the coordinate from the text file into another listbox. Here is the code i have written: C. Copy Code. Posted Apr am Member Add a Solution. Kenneth Haugland Apr am. Any chance that you can save it in a XML file instead? Should make it easier to deal with the file reading etc, as all the information will be in one place?

Member Apr am. Kenneth Haughland. Thank you for your response I appreciate it. How will I be able to save it to XML file. I am new to c programming. This is my first project. Abdul Samad KP Apr am.

I think there is a mistake in your code for reading the text file change if System. Active 1 year, 8 months ago. Viewed 2k times. Net is limited and i am really trying hard to figure this problem out Add Path.

GetFileName files[i]. FullName ; once the listbox displays the all. ToString ;. Improve this question. Arvind Gupta. Arvind Gupta Arvind Gupta 5 4 4 bronze badges. Then just do TextBox1. Add a comment.



0コメント

  • 1000 / 1000