colinreedy674 colinreedy674 - 1 year ago 102
C# Question

Dynamic listview header text

I have this code that will load a bunch of .txt files (when selected from the combobox), and display the data in a listview:

private void cmbFiles_SelectedIndexChanged(object sender, EventArgs e)
string[] content = File.ReadAllLines(@"Credentials/" + cmbFiles.SelectedItem);
int colCount = 0;
foreach (string line in content)
string[] substrings = line.Split('|');
colCount = Math.Max(colCount, substrings.Count());
ListViewItem listItem1 = new ListViewItem(substrings[0]);
for (int i = 1; i < substrings.Count(); i++)
listItem1.SubItems.Add(new ListViewItem.ListViewSubItem(listItem1, substrings[i]));
for (int i = 1; i <= colCount; i++)

This works great, but doesn't show any column header text, i'm not sure the best way to display the header text, it will need to change randomly depending on what file is displayed, any tips or views on the best way to go would be appreciated!

Answer Source

You should change ListView.View Property to Details.

        lvContent.View = View.Details;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download