views:

800

answers:

3

I've done it one thousand of times and it works but now .... not :(

Am I doing something wrong here because nothing is shown in grid ?

namespace theGridIsNotWorking
{
using System;
using System.Collections.Generic;
using System.Windows.Forms;

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        var items = new List<Item>();

        items.Add(new Item(){ TheName = "first"});
        items.Add(new Item(){ TheName = "Second"});
        items.Add(new Item(){ TheName = "Third"});

        dataGridView1.DataSource = new List<Item>(items);
    }

    public class Item
    {
        public string TheName;
    }
}
}

Nothing spectaculos .... but really sad.

+1  A: 
BindingList<Notification>(notifications);

shouldn't it be

BindingList<Notification>(activeNotifications);

?

bbmud
sorry for mistake ... it's gramatically only ... this is a demo purpose ... with activeNotifications has to be, doesn't work :(
ruslander
I thought it will be easy... I tried the code and it works fine. First, are you sure that this code is run? Second, did you set anything on DataGridView?
bbmud
on my machne the grid is still empty ... I'm using vs2008, .net 3.5 ... :(
ruslander
+2  A: 

Try BindingListView. Easiest way to bind a List<T> to a DGV.

Chris Doggett
+2  A: 

I think the problem is that TheName is a member variable, but you need a property. Try the following for the Item class:


      public class Item
      {
         public string TheName;

         public string TheNameProperty
         {
            get
            {
               return TheName;
            }
         }

         public Item(string name)
         {
            TheName = name;
         }
      }

SwDevMan81