views:

369

answers:

3

seems simple enough, I want to take a generics list of integers and display them on a datagridview. google comes back with plenty of results on displaying custom classes in a datagridview, but not a list of int. when I just submit the list as the datasource, nothing shows.

I tried using

dim _CheckIns as new list(of integer)
_checkins.add(1577)
_checkins.add(1999)
Dim bl As New System.ComponentModel.BindingList(Of Integer)(Me._CheckIns)
me._dg.datasource=bl

then tried bindingsource to go with the binding list

dim bs as new BindingSource()
bs.datasource=bl
me._dg.datasrouce=bs

No luck so far.

+1  A: 

Try databinding bs after giving it a datasource

bs.DataBind()
Jonathan Mayhak
I'm not finding a member of BindingSource, BindingList, nor datagridview called DataBind()?
Maslow
A: 

I believe the grid is the object that needs to be databound:

me._dg.DataSource = bs
me._dg.DataBind()
Jeff Meatball Yang
I'm not finding a member of BindingSource, BindingList, nor datagridview called DataBind()? This is a windows forms application, I do recall a databind in asp.net perhaps?
Maslow
A: 

Won't be that easy, the databinding mechanism looks for properties and Int32 doesn't have any. You can test it with a List< int?>, it'll show HasValue and Value colums.

So you'll have to wrap it in a class:

class MyInt
{
   public int Value { get; private set; }
   public MyInt(int v) { Value = v; }
}

I made it immutable to comply with current best practices.

Henk Holterman
oh neat, I read once that you could make the Set private, didn't pay attention to the syntax, and now see lots of places I can use that trick.
Maslow