0

I've a ListView (named ListView1). I added 4 columns (with visual editor, property Column): NumeroLista,OrdenLista,NumElementos,TiempoOrdenamiento.

I'm sure the code is reached because before it is in a function called directly from class constructor. I'm trying to fullfil it with the following code but it keeps blank (please notice: the arrays I'm using are inizialized in another part of the code):

int idx;
string tmp;
string[][] linea = new string[numListas][];
for (idx = 0; idx < numListas; idx++)
{
    linea[idx] = new string[3];
    linea[idx][0] = Convert.ToString(idx);
    switch(OrdenListas[idx]){
        case 0: linea[idx][1] = "Crescente"; break;
        case 1: linea[idx][1] = "Decrescente"; break;
        case 2: linea[idx][1] = "Aleatorio"; break;
        default: linea[idx][1] = "No especificado"; break;
    }
    linea[idx][2] = Convert.ToString(LongitudListas[idx]);
    ListViewItem lvi = new ListViewItem();
    lvi.SubItems.Add(linea[idx][0]);
    lvi.SubItems.Add(linea[idx][1]);
    lvi.SubItems.Add(linea[idx][2]);
    lvi.SubItems.Add("test");
    listView1.Items.Add(lvi);
    listView1.Refresh();
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
dragonmnl
  • 14,578
  • 33
  • 84
  • 129
  • Have you set the `View` property of the Listview to `Details`? Also, refreshing the listview after item insertion is not needed. – ken2k Feb 20 '12 at 09:14

1 Answers1

0

You probably forget to set listview's ListView.View to Details

Hope this helps.

Tigran
  • 61,654
  • 8
  • 86
  • 123
  • Thank you. It works. but... it displays second,third and fourh column (first attribute on second column,second attribute on third column,..). How could I fix it? – dragonmnl Feb 20 '12 at 09:39
  • The first column shows the text of the ListViewItem itself. So pass `linea[idx][0]`to the ListViewItem constructor instead of using a sub item for it. – okrumnow Feb 20 '12 at 09:44
  • Do you mean pass a string ( linea[idx][0] ) + an array (of the elements left) so in total two elements? – dragonmnl Feb 20 '12 at 10:04