我将对象列表绑定到datagridview并且显示有问题: 这是我的自定义类
public class Line
{
private int _sequence;
public int Sequence {get { } set { }}
private string _dataTime;
public string DataTime {get { } set { }}
private string _content;
public string Content {get { } set { }}
public Line(int sequence, string dateTime, string content)
{
_sequence = sequence;
_dataTime = dateTime;
_content = content;
IsBookmarked = false;
}
}
我绑定了List:
List<Line> lines = new List<Line>();
// lines is initialized with values
DataGridView dataGrid = new DataGridView();
dataGrid.DataSource = Lines
DataGridView显示列表的内容而不会出现问题。但是列很窄,所以我想格式化列:
dataGrid.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
在这里我得到一个例外:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
在运行时检查dataGrid.Columns.Count我看到它是'0'而不是我所期望的3。
答案 0 :(得分:0)