As an exercise to learn C# programming, I've been developing a tiny application that connects to an Oracle database, and sends a SQL query to it. The results, if any, are then displayed in a ListView control using the "Details" viewing mode, so that one can easily see the database's column names and the rows.

Here's an extract of the code that handles displaying the results.

if (textBox1.Text.Length > 0)
{
OleDbCommand myCmd = new OleDbCommand(textBox1.Text, oleDbConnection1);
OleDbDataReader myReader = myCmd.ExecuteReader();
listView1.Columns.Clear();
listView1.Items.Clear();
colcnt = myReader.FieldCount;

for (i = 0; i < colcnt; i++)
{
listView1.Columns.Add(myReader.GetName(i), 150, HorizontalAlignment.Left);
}

while (myReader.Read())
{
ListViewItem item = new ListViewItem(myReader.GetValue(0).ToString());

for (i = 1; i < colcnt; i++)
{
item.SubItems.Add(myReader.GetValue(i).ToString());
}
listView1.Items.Add(item);
}
myReader.Close();
}

This works just fine. Now if I try to use -2 or -1 for the column width in the listView1.Columns.Add() call, which are magical values to tell the ListView control to autosize based on the largest subitem or on the column's name length, it doesn't work anymore.

What's happening in that case is that it looks like there is only one column, with no text, 0 rows, and no horizontal scrolling bar either.

Any clues?

Thanks in advance,
Maxime