Russell Steen
Russell Steen

Reputation: 6612

Programmatic data in .NET Winforms DataGrid

I'm getting a weird behavior with a datagrid. No matter what I do, it's ordering the columns arbitrarily and adding all the columns in the objects.

I'm using .NET 3.5, with a winforms datagrid. The Datasource is set at runtime, not design time. I've tried defining the columns in the GDI, but it ignores the order. Even if I only define one item, it displays the every public property on the list I pass in.

List<EventLog> events = service.GetEvents();
EventLogList.DataSource = events;
EventLogList.AutoGenerateColumns = false;
EventLogList.Refresh();

EventLog is an object generated by Linq2Sql. It passes back a view. The grid always shows every column, regardless of what I do to the columns object in the designer.

Upvotes: 0

Views: 304

Answers (2)

Russell Steen
Russell Steen

Reputation: 6612

Set AutoGenerateColumns = false BEFORE setting the datasource....

Upvotes: 0

djdd87
djdd87

Reputation: 68466

Is the AutoGenerateColumns property set to false?

Upvotes: 2

Related Questions