Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How do I add a DataTable to a ListView?

$
0
0

How do I add a DataTable to a ListView?

Consider this code:

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            addData();
        }

        public void addData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Column 1");
            dt.Columns.Add("Column 2");
            dt.Rows.Add(new object[] { "Dummy", "Data"});
            dataGridView1.DataSource = dt;
        }
    }    

If I would do the same with a ListView, and add the same data to it, how would I go about to do that?
"listView1.DataSource" doesn't seem to work.


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>