I’m a newbie trying to make an Windows Form App via Visual Studio.
I am trying to read data from my SQL Server’s database and display this on a table in the Forms App.
I’m using ListView for this.
To understand how to even use ListView, I’ve spent many days mainly using the Microsoft’s Documentation. I have some questions to ask the expertise here.
Q1. What is the purpose of a SubItem and when do we need to use it ?
What I understand so far is that ListView is just a way to display items, where the items are stored under its Property ‘Items’. Each Item is an instance of the class ListViewItem, where itself has a Property ‘SubItems’. Each SubItem is an instance of the class ListViewItem.ListViewSubItems.
I’ve already read the documentation for ListViewItem.ListViewSubItems and they say that a SubItem is a way to put in additional details about the Item. Yet, when I see programmers add data in a row of their ListView (treating it like a table), they do so by first creating a ListViewItem to insert their first data (data in col0) and then inserting their subsequent data (data in col1, col2,…) by putting it inside of ListViewItem’s Subitems.
E.g.,
row = new ListViewItem(reader[0].ToString()); // column 0
row.SubItems.Add(reader[1].ToString()); // column 1
row.SubItems.Add(reader[2].ToString()); // column 2
row.SubItems.Add(reader[3].ToString()); // column 3
listView.Items.Add(row);
I do not understand this system/approach of inserting data into ListView. Why the data being inserted into columns 1, 2 and 3 are termed as “SubItems” of ListViewItem ? Yet data of column 0 is the “main” ListViewItem ?
Plant is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.