Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3627558
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:54:13+00:00 2026-05-18T23:54:13+00:00

The DataGridView has a property DataSource that can simply be assigned to a DataTable

  • 0

The DataGridView has a property “DataSource” that can simply be assigned to a DataTable to populate it. This means we don’t have to worry about the names/number of columns in the DataTable.

But, I haven’t found a similar way of populating a ListView. It seems that you need to know how many columns the DataTable has and the names of each in order to do this, making it much more difficult.

Can anyone suggest an easy way to populate a ListView like we can with a DataGridView?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:54:14+00:00Added an answer on May 18, 2026 at 11:54 pm
    private void LoadList()
    {
        // Get the table from the data set
        DataTable dtable = _DataSet.Tables["Titles"];
    
        // Clear the ListView control
        listView1.Items.Clear();
    
        // Display items in the ListView control
        for (int i = 0; i < dtable.Rows.Count; i++)
        {
            DataRow drow = dtable.Rows[i];
    
            // Only row that have not been deleted
            if (drow.RowState != DataRowState.Deleted)
            {
                // Define the list items
                ListViewItem lvi = new ListViewItem(drow["title"].ToString());
                lvi.SubItems.Add (drow["title_id"].ToString());
                lvi.SubItems.Add (drow["price"].ToString());
                lvi.SubItems.Add (drow["pubdate"].ToString());
    
                // Add the list items to the ListView
                listView1.Items.Add(lvi);
            }
        }
    }
    

    Find sorting etc also at –
    http://www.akadia.com/services/dotnet_listview_sort_dataset.html

    Modified –

    // Clear the ListView control
                listView1.Items.Clear();
                int ColCount = dtable.Columns.Count;
                //Add columns
                for (int k = 0; k < ColCount; k++)
                {
                   listView1.Columns.Add(dtable.Columns[k].ColumnName);
                }
                // Display items in the ListView control
                for (int i = 0; i < dtable.Rows.Count; i++)
                {
                    DataRow drow = dtable.Rows[i];
    
                    // Only row that have not been deleted
                    if (drow.RowState != DataRowState.Deleted)
                    {
                        // Define the list items
                        ListViewItem lvi = new ListViewItem(drow[0].ToString());
                        for (int j = 1; j < ColCount; j++)
                        {
                            lvi.SubItems.Add(drow[j].ToString());                        
                        }
                        // Add the list items to the ListView
                        listView1.Items.Add(lvi);
                    }
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Winforms app that has a DataGridView that is databound at runtime.
I have a DataGridView in a Winforms app that has about 1000 rows (unbound)
I have a DataGridView that's bound to a DataSet. It has columns DateCreated, Weight,
I have a datagridview that has set colors depending on the status of the
Say a DataGridView has its DataSource property set to a DataView instance. DataGridView dgv;
I have a WinForm that has a DataGridView table. It is bound to a
I have a DataTable that has a boolean column called [Invalid]. I need to
Why this DataGridView control has a gray strips? How can I overcome this problem?
I have a problem with my DataGridView.DataSource and it has consumed me a lot
I have a DataTable which is bound to DataGridView . DataTable has several columns

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.