Multiple Columns in listview

2019-08-02 02:55发布

I am writing the following code in C# to show data in multiple columns in a listView but it only shows the first element of the array,

ListViewItem item = new ListViewItem(new []{txtTitle.Text,txtRatings.Value.ToString(),cmbGenre.Text});
lstMovie.Items.Add(item);

the output in the list view is just the first element. How do I get all three elements.

2条回答
男人必须洒脱
2楼-- · 2019-08-02 03:39

Have you added the 3 columns to your listview before trying to populate it? Something like:

lstMovie.Columns.Add("Title");
lstMovie.Columns.Add("Ratings");
lstMovie.Columns.Add("Genre");
查看更多
forever°为你锁心
3楼-- · 2019-08-02 03:49

The data was inserted but listview was not displaying it, set listView's View property to Details

lstView.View = View.Details;
查看更多
登录 后发表回答