手动填充数据,为什么DataGridView不显示数据???
数据列已在设计视图中建立了,这段代码是向控件中填充数据,但为什么能显示出行,但单元格中没有任何数据,数据集中是存在数据的。
this.view.Rows.Clear();
DataTable bindTable = searchResult.Tables[0];
for (int i = 0; i < bindTable.Rows.Count; i++)
{
DataGridViewRow row = new DataGridViewRow();
DataGridViewTextBoxCell id = new DataGridViewTextBoxCell();
id.Value = bindTable.Rows[i][ "ID "].ToString();
id.ValueType = typeof(string);
row.Cells.Add(id);
DataGridViewTextBoxCell name = new DataGridViewTextBoxCell();
name.Value = bindTable.Rows[i][ "Name "].ToString();
row.Cells.Add(name);
DataGridViewTextBoxCell amount = new DataGridViewTextBoxCell();
amount.Value = bindTable.Rows[i][ "Amount "].ToString();
row.Cells.Add(amount);
DataGridViewTextBoxCell certificationCode = new DataGridViewTextBoxCell();
certificationCode.Value = bindTable.Rows[i][ "BatchNumber "].ToString();
row.Cells.Add(certificationCode);
DataGridViewTextBoxCell memberName = new DataGridViewTextBoxCell();
memberName.Value = bindTable.Rows[i][ "Member_Name "].ToString();
row.Cells.Add(memberName);
DataGridViewTextBoxCell quarantineDate = new DataGridViewTextBoxCell();
quarantineDate.Value = bindTable.Rows[i][ "QuarantineDate "].ToString();
row.Cells.Add(quarantineDate);
DataGridViewTextBoxCell status = new DataGridViewTextBoxCell();
status.Value = Constants.GetPreQuarantineStatusText(int.Parse(bindTable.Rows[i][ "Status "].ToString()));
DataGridViewLinkCell linkCell = new DataGridViewLinkCell();
if ((int)bindTable.Rows[i][ "Status "] == (int)Constants.PermitQuarantineStatus.Butchered)
{
linkCell.UseColumnTextForLinkValue = false;
}
else
{
linkCell.UseColumnTextForLinkValue = true;
row.Cells.Add(linkCell);
}
this.view.Rows.Add(row);
}
------解决方案--------------------帮你顶一下