views:

32

answers:

2

Currently I am doing:

var items = from t in entity.Items
    select new
    {
        Name = t.ItemName,
        Description = t.ItemDescription
    };


myDataGridView.DataSource = items.ToList();

The problem is that when bound to the DataGridView, I get two columns of "Name" and "Description". I want to rename these to "Item Name" and "Item Description" (example).

If I add an unbound Column to the datagridview, it just gets displayed along with my columns. I can not seem to create a databound column.

A: 

Can you post the grid's source?

You'll need AutogenerateColumns="false" to add columns manually.

To change the header text, you should be able to do the following:

 <Columns>
   <asp:BoundField DataField="Name" HeaderText="Item Name" ReadOnly="True" />
 // .. etc
Jim Schubert
Sorry, I didn't specify but I am speaking about winforms. I modified the post appropriately.
esac
I think I misread ado.net as asp.net.
Jim Schubert
A: 

I found out how to use drag and drop of an object data source to bind the columns to a DataGridView directly, which allows me to change the header text.

esac