datagridview 数据动态添加

for (Int32 i = 0; i <= tasklist.Rows.Count - 1; i++) {
	DataG1.Rows.Add();
	for (Int32 j = 0; j <= tasklist.Columns.Count - 1; j++) {
		object tempdata = tasklist.Rows(i)(j);
		if (object.ReferenceEquals(tempdata, System.DBNull.Value)) {
			DataG1.Rows(i).Cells(j).Value = null;
		} else {
			if (Information.IsDate(tempdata)) {
				//'备注内容为日期型时转换为string
				if (DataG1.Columns(j).HeaderText == "备注") {
					DataG1.Rows(i).Cells(j).Value = Convert.ToDateTime(tempdata).ToString();
				} else {
					DataG1.Rows(i).Cells(j).Value = Convert.ToDateTime(tempdata);
				}
			} else {
				DataG1.Rows(i).Cells(j).Value = tempdata;
			}
		}
	}
}
原文地址:https://www.cnblogs.com/swarb/p/9924420.html