How add column to IEnumerable or grid it's bound to?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ronald S. Cook

    How add column to IEnumerable or grid it's bound to?

    I bring back a list of Employees as an IEnumerable of Employee... columns
    include EmployeeId, EmployeeLastNam e, etc.

    I want to bind the IEnumerable to a datagrid BUT I want the grid to have an
    extra column, a checkbox for the user to select some employees and not
    others.

    I will then use this information, but the checkbox column does not
    correspont to a column in the Employee table to get updated.

    Is there a way I can add a column to an IEnumerable? What is a "normal" way
    to do what I'm trying to do?

    I can convert the IEnumerable to a DataTable and add a column to it and then
    bind to the datagrid, but that seems like a hack.

    Thanks for any help,
    Ron

  • Jeff Winn

    #2
    Re: How add column to IEnumerable or grid it's bound to?

    Well, I tend to stay away from the DataGrid control - however as far as I
    know when binding directly to an object collection it creates the grid based
    on the object you're using. Just add a boolean property to your Employee
    object with a get and set accessor. When the user modifies the checkbox in
    the column, the object in your collection will be updated as well.

    If this solution does not work for you, we need more information how your
    data layer is setup when you're persisting data from your application back
    to the database.

    "Ronald S. Cook" <rcook@westinis .comwrote in message
    news:4DAE8C11-455A-4745-9707-B058AA8FA971@mi crosoft.com...
    >I bring back a list of Employees as an IEnumerable of Employee... columns
    >include EmployeeId, EmployeeLastNam e, etc.
    >
    I want to bind the IEnumerable to a datagrid BUT I want the grid to have
    an extra column, a checkbox for the user to select some employees and not
    others.
    >
    I will then use this information, but the checkbox column does not
    correspont to a column in the Employee table to get updated.
    >
    Is there a way I can add a column to an IEnumerable? What is a "normal"
    way to do what I'm trying to do?
    >
    I can convert the IEnumerable to a DataTable and add a column to it and
    then bind to the datagrid, but that seems like a hack.
    >
    Thanks for any help,
    Ron
    >

    Comment

    Working...