Jak powiązać listę z dataGridView?

Wydaje mi się, że biegam w kółko i robię to w ostatnich godzinach.

Chcę zapełnić datagridview z tablicy łańcuchów. Przeczytałem, że nie jest to możliwe bezpośrednio i że muszę utworzyć niestandardowy typ, który przechowuje ciąg jako własność publiczną. Zrobiłem więc klasę:

public class FileName
    {
        private string _value;

        public FileName(string pValue)
        {
            _value = pValue;
        }

        public string Value
        {
            get 
            {
                return _value;
            }
            set { _value = value; }
        }
    }

jest to klasa kontenera i po prostu ma właściwość o wartości ciągu. Wszystko, czego chcę teraz, to ten ciąg znaków, który ma się pojawić w datagridview, kiedy wiążę jego źródło danych z listą.

Mam też tę metodę, BindGrid (), którą chcę wypełnić datagridview. Oto jest:

    private void BindGrid()
    {
        gvFilesOnServer.AutoGenerateColumns = false;

        //create the column programatically
        DataGridViewTextBoxColumn colFileName = new DataGridViewTextBoxColumn();
        DataGridViewCell cell = new DataGridViewTextBoxCell();
        colFileName.CellTemplate = cell; colFileName.Name = "Value";
        colFileName.HeaderText = "File Name";
        colFileName.ValueType = typeof(FileName);

        //add the column to the datagridview
        gvFilesOnServer.Columns.Add(colFileName);

        //fill the string array
        string[] filelist = GetFileListOnWebServer();

        //try making a List<FileName> from that array
        List<FileName> filenamesList = new List<FileName>(filelist.Length);
        for (int i = 0; i < filelist.Length; i++)
        {
            filenamesList.Add(new FileName(filelist[i].ToString()));
        }

        //try making a bindingsource
        BindingSource bs = new BindingSource();
        bs.DataSource = typeof(FileName);
        foreach (FileName fn in filenamesList)
        {
            bs.Add(fn);
        }
        gvFilesOnServer.DataSource = bs;
    }

Wreszcie problem: tablica ciągów wypełnia się, lista jest tworzona ok, ale otrzymuję pustą kolumnę w datagridview. Próbowałem też bezpośrednio datasource = list <>, zamiast = bindingsource, nadal nic.

Naprawdę doceniłbym radę, to doprowadzało mnie do szału.

Dziękuję Ci

questionAnswers(5)

yourAnswerToTheQuestion