简体   繁体   中英

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.

AutoGenerateColumns属性是否设置为false?

在设置数据源之前,设置AutoGenerateColumns = false。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM