C
CSharp-Jay
Hey all, I am really having the worst time trying to figure out the
way the listview control works. Basically as a side project I am
working on an Address Book, and in it I have a listview control with
the obvious columns(First Name, City, State, etc). When the program
is closed the data gets saved to a comma delimited file called
data.dat. When the program is opened data.dat is automatically read
into a string array line by line which is then supposed to add each
array element into its appropriate column in the listview. But I
cannot get anything to show up on the control >< The program doesn't
crash and bug checks show it's breaking up the array appropriately,
but still a blank listview stares at me. I have to admit this is like
my second time using it and well...I am at a loss right now, I will
submit a code snippet but mind you it is probably a wee bit jacked by
now since I can't figure out how to get this done.
ListViewItem items;
sw = new StreamWriter("data.txt", true);
sw.Close();
sr = new StreamReader("data.txt");
string line;
string[] lines;
while ((line = sr.ReadLine()) != null)
{
lines = line.Split(',');
items = new ListViewItem();
for (int i = 0; i < lines.Length; i++)
{
if (i == 0)
items.Text = lines;
else
items.SubItems.Add(lines);
}
}
sr.Close();
way the listview control works. Basically as a side project I am
working on an Address Book, and in it I have a listview control with
the obvious columns(First Name, City, State, etc). When the program
is closed the data gets saved to a comma delimited file called
data.dat. When the program is opened data.dat is automatically read
into a string array line by line which is then supposed to add each
array element into its appropriate column in the listview. But I
cannot get anything to show up on the control >< The program doesn't
crash and bug checks show it's breaking up the array appropriately,
but still a blank listview stares at me. I have to admit this is like
my second time using it and well...I am at a loss right now, I will
submit a code snippet but mind you it is probably a wee bit jacked by
now since I can't figure out how to get this done.
ListViewItem items;
sw = new StreamWriter("data.txt", true);
sw.Close();
sr = new StreamReader("data.txt");
string line;
string[] lines;
while ((line = sr.ReadLine()) != null)
{
lines = line.Split(',');
items = new ListViewItem();
for (int i = 0; i < lines.Length; i++)
{
if (i == 0)
items.Text = lines;
else
items.SubItems.Add(lines);
}
}
sr.Close();