【发布时间】:2013-11-24 11:30:05
【问题描述】:
我的 Datagrid 填充了正确的行数,但没有数据显示。 所有行都显示为空列。
这可能是什么原因?
这是我第一次使用datagridview。
public void BindDataGridView(DataGridView dgv, Hashtable ht) {
DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("test");
//now build our table
dt.Columns.Add("col1", typeof(string));
dt.Columns.Add("col2", typeof(Int32));
IDictionaryEnumerator enumerator = ht.GetEnumerator();
DataRow row = null;
while (enumerator.MoveNext()) {
string index = (string)enumerator.Key; // boekingsREf
MyClass a = (MyClass)enumerator.Value;
row = dt.NewRow();
row["col1"] = index;
row["col2"] = a.number;
dt.Rows.Add(row);
}
//dgv.DataSource = ds.Tables[0];
dgv.DataSource = ds.Tables[0];
}
【问题讨论】:
标签: c# datagridview hashtable