[RESOLVED] Best way to repopulate ListView in vb.Net
(Migrating from vb6 to vbNet) I have an Excel file I need to leave undisturbed. I can loop through it and populate a ListView with columns during form load. After that I want to repopulate the ListView, changing column headers and presenting the same data in a different order or with some columns absent. If I created my Excel application As Object when loading the form it is obviously no longer available from a new button as the button is Private. What is the convention for doing this? Does ADO.NET work with Excel? I want to keep the data source invisible (.visible = False) yet manipulate it for the ListView. I could create a text fiile from the Excel and loop through that in each button code. That seems a poor way to do it. There will be no input from the user, just reading from 22 columns displaying only 3 or 4 of them at a time in ListView. Strategy needed please and maybe one or two code examples from a guru.
Re: Best way to repopulate ListView in vb.Net
I would suggest using ADO.NET to load your data into a DataTable, binding that to a BindingSource and binding that to a DataGridView. It's a once only operation and then you can sort and filter the data using the BindingSource and you can hide and show columns through the DataGridView. You treat Excel much as you do Access when using ADO.NET, with a few small changes. See www.connectionstrings.com for the details.
Re: Best way to repopulate ListView in vb.Net
Thanks for this. Those 'few small changes' you mention between Excel and Access? I have found connection examples such as:
public string conString=
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\PersonDatabase.mdb";
Does this connection string still work if I use an Excel file too?
Re: Best way to repopulate ListView in vb.Net
The site I provided a link to provides connection strings specifically for Excel.