TechnoTone Posted March 16, 2004 Posted March 16, 2004 I have a ListBox with its datasource set to a collection. I want to update the ListBox to display the recent changes made to the collection but I can't get it to work. There seems to be no method to do this directly and I've tried resetting the datasource but to no avail. What's worse - if I first set the DataSource to Nothing then set it back to the collection, the list will then contain my collection but each item has no text so I can't see them. I can select them but I can't see them. How can I update the listbox to display the changes made to the datasource collection? Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
TechnoTone Posted March 16, 2004 Author Posted March 16, 2004 Anyone - please. I'm under a bit of pressure to get this sorted. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
Denaes Posted March 16, 2004 Posted March 16, 2004 I'm not sure about a collection. I'd load everything from the collection into a datatable and use a dataview to filter/sort it all. Thats what I did and it works perfect. A DataTable is also a collection and you're not limited to the number of rows. Quote
TechnoTone Posted March 16, 2004 Author Posted March 16, 2004 But I wanted to keep things simple. Seems strange that you can load a collection into a listbox by binding it but you can't refresh it. I have found a workaround however. Set the datasource to a New ArrayList first then set it back to the collection. I don't exactly like it but it'll do. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
Denaes Posted March 16, 2004 Posted March 16, 2004 But I wanted to keep things simple. Seems strange that you can load a collection into a listbox by binding it but you can't refresh it. I have found a workaround however. Set the datasource to a New ArrayList first then set it back to the collection. I don't exactly like it but it'll do. A lot of things don't work the same/correctly when you've got the datasource on. Refresh looks into it's own item collection, not the datasource. Sort tries to sort its own item collection and throws an exception if it's databound. This is why I skip the hoopla and use a datatable. Its a better version of a collection for non performance needs. It acts like a collection in terms of not needing an index, expandability, but is limited to text. With a collection, you can have "A" Key, but you can't get it to tell you what the key is again (like printing a list of Key - Information) that I can tell. A DataTable can have a "Key" (just call a column Key, or whatever you want) and also can link up to many other text items rather than one, you just add more columns. You can even use SQL statements (or VB) to play with data and put it in another row. Frex: You collect FirstName and LastName and put them into a DataTable with a ClientID# as a Key of sorts. You can then have another column called "FullName" which has LastName, Firstname. You can feed this column to a list/combo box, which can only accept one column, but you've got two columns worth of data being displayed. Then when you use it, you set it to a DataView, you can filter and sort very easily the change IS reflected by a listbox. Using collections you'd have to build custom objects to store this sort of data, and I'm kinda sketchy on how a List/combobox would display a custom object within a collection. Other than that, you'd have to have parallel Arrays/Collections to get this much data synched up. I'm glad you got it working though... had to fool it into changing datasources :p Quote
Tryster Posted March 16, 2004 Posted March 16, 2004 ...What's worse - if I first set the DataSource to Nothing then set it back to the collection, the list will then contain my collection but each item has no text so I can't see them. I can select them but I can't see them. This behavior is caused by the List control clearing the DisplayMember field when you set the datasource to Nothing. If you reset the DisplayMember property to it's original value after setting the DataSource property it should work fine. Quote
TechnoTone Posted March 16, 2004 Author Posted March 16, 2004 Denaes: I see what you're saying but will a DataTable allow me to store a collection of objects that have their own code? Tryster: I tried that but it didn't help. It is very confusing. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
Denaes Posted March 16, 2004 Posted March 16, 2004 (edited) Denaes: I see what you're saying but will a DataTable allow me to store a collection of objects that have their own code? No. It displays text. If you can figure out a way to convert a string into code (I don't know how to do it in vb.net) then that would work. A DataTable would store your information to display and could link to the Key in your collection, which is too much work if you can do it all in a single object within your collection. That's why I said that a Datatable is superior for displaying/accessing text, especially multiple items that need to stay parallel, but won't do much good for non-string objects. Don't get me wrong, if you're suave enough, you can do a LOT with collections. A DataTable is just a collection of DataRows. A DataRow is just a collection of DataColumns. I'm pretty sure DataCoumns are either a collection or array of strings. You can do the same yourself to meet whatever needs you may have without resorting to DataTables, it just happens to work well with DataView and work well out of the box as a great way to manipulate groups of strings, including displaying them. Just curious for the sake of learning, how do you store code in a collection? I have some ideas involving classes/objects, but I'd like to see how its done. Edited March 16, 2004 by Denaes Quote
TechnoTone Posted March 17, 2004 Author Posted March 17, 2004 No. Just curious for the sake of learning, how do you store code in a collection? I have some ideas involving classes/objects, but I'd like to see how its done. The collection contains objects and those objects have properties and methods that perform certain relevant tasks. That's the code I was referring to. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.