1,978
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 从数据库读取数据绑定到相应的DataGridView中。
/// </summary>
/// <param name="tableName"></param>
/// <param name="dgv"></param>
private void LoadDateToDgv(DataSet ds,DataGridView dgv,PageCut.PageCut pc)
{
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
dgv.DataSource = ds.Tables[0];
string stationName="";
for (int i = 0; i < dgv.Rows.Count; i++)
{
stationName = GetStationNameByID(ds.Tables[0].Rows[i]["station_id"].ToString());
dgv.Rows[i].Cells[2].Value = stationName; //这就是我要赋值的那个列:站名。是我手动在gridview控件上面添加的一个未绑定列。然后在这里给他赋值。
}
dgv.Refresh();
InitPageCut(ds, dgv, pc);
}
}
this.dataGridView1.DataSource = dt;//绑定数据
this.dataGridView1.Rows[1].Cells[0].Value = "69";//修改2行第一列