[RESOLVED] Best way to repopulate ListView in vb.Net-VBForums
Results 1 to 4 of 4

Thread: [RESOLVED] Best way to repopulate ListView in vb.Net

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    190

    Resolved [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.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,314

    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.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    190

    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?

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,314

    Re: Best way to repopulate ListView in vb.Net

    The site I provided a link to provides connection strings specifically for Excel.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.