• Advertisement
Sign in to follow this  

Creating a table in C#

This topic is 3867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a c# windows form that I want to contain a table of items. this list of items can be added to or have items removed from it at any time, and contains (and displays) several items from the class (name, ID number, etc). Currently the data for this list is stored in an enumerated list ( based on: http://msdn2.microsoft.com/en-US/library/ms173233(VS.80).aspx). I want to display this in a table, and decided to use a ListBox to accomplish this (if theres a better way of displaying the information i'm all ears). However, ListBox throws an exception if you try to make it look at the list, and it seems it only likes DataSet items. I then made the data set, but I can't figure out how to add items to it (even just explicitly as strings). Anyone able to help with any of these issues?

Share this post


Link to post
Share on other sites
Advertisement
Winegums,

First, I'd recommend using a ListView, rather than a ListBox. ListViews provide more flexibility in appearance and behavior than a ListBox, and you can set the ListView view to "Details" in order to have columns for each of the properties of the object you want displayed.

For more info, look HERE.

Secondly, your problem with binding to the list is that you're trying to bind to an IEnumerable generic. The Binding object requires the DataSource be either a DataSet, DataTable, DataView, DataViewManager, or object that implement the IList interface if you're trying to bind a set. Likely, you just need to store your data in something that implements IList. My personal preference is ArrayList if you dont need something that's strongly typed. If you do, you can of course create your own list based on the List<> generic.

Here's some more information on the binding.

Here's the info for ArrayList

Cheers!

Share this post


Link to post
Share on other sites
thanks for the replies, i certainly feel i'm on the right track now, but i'm sort of swamped in the whole data binding thing.

the examples i've looked at on MSDN have been a bit confusing. currently i have an ArrayList called arrayList. adding stuff to that seems to work fine which is cool.

but binding it to the ListView is the bit i'm not sure about. I figured the next step is to link the ListView to the ArrayList, but I'm not sure how use the Add() function. I don't understand what the parameters mean, and the examples on MSDN seem to work with data sets, which look like they're different from ArrayLists?

Share this post


Link to post
Share on other sites
ok i've managed to figure out how to bind things, but what part of ListView am i using with DataBindings.Add() in order to link the data source to the ListView?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement