Binding to custom collection - select columns to display

Hi -

I am trying to bind a datagrid (windows forms environment, VS2003) to a custom collection(not an arraylist) - it works, and I am really happy about it, but when I bind the collection the grid shows all of the additional columns that i don't want displayed.

Now I've read loads of articles about binding database tables (Datasets) to the grid and using the TableStyles collection, however all of these notes are(like i said previously) based on dataset binding.

I have tried creating my own table style based on the name of my collection but it still seems to show all of the data.

I even tried some code from a Frans Bouma's Blog(http://weblogs.asp.net/fbouma/articles/115837.aspx), attempting to create an attribute that would allow me to 'hide' aspects of the object from databinding... that didn't work either....Sad

Anyone got any sample code or ideas of how i can achieve this

Cheers

Mike (in BindingDesparation!)


Answer this question

Binding to custom collection - select columns to display

  • Tara

    On the collection I am implementing :

    CollectionBase , ICloneable , IBindingList


    On the object (that is in the collection) i am implementing

    ICloneable , IEditableObject

    Going to try googling for Browseable=false, and see what that gives me - thanks for the starting point.


  • nelson_r

    ok - that got it - i forgot a reference to component model in my collection... Whoops...

    Thanks for that!


    Mike (no longer in binding desperation)

  • micber

    I'm not sure what interfaces you've implemented on your custom collection, but assuming you're not implementing ITypedList, you can do the following to hide a property (this shows how to hide the ID property):


    private string _id = string.Empty;

    [Browsable(false)]
    public string ID
    {
     get { return _id; }
     set { _id = value; }
    }

     



    Joe Stegman
    The Windows Forms Team
    Microsoft Corp.

    This posting is provided "AS IS" with no warranties, and confers no rights.


  • Binding to custom collection - select columns to display