代码附上:
void UCHouseholdRegisterInfoList_Load(object sender, EventArgs e)
{
BusinessService.CommunityBasicInfo.HouseholdRegisterInfoService service = new BusinessService.CommunityBasicInfo.HouseholdRegisterInfoService();
IList<Tc_ge_rpr> householdInfoList= service.GetHouseholdRegisterInfoList();
this.dgvHouseholdRegisterInfo.DataSource = householdInfoList;
UIHelper.AddIndexToView(dgvHouseholdRegisterInfo);
}
UIHelper方法如下
/// <summary>
/// 向datagridview添加自动编号
/// </summary>
/// <param name="view"></param>
public static void AddIndexToView(DataGridView view)
{
try
{
view.Columns.Add(new DataGridViewTextBoxColumn() {Name = "dataGridviewIndex", HeaderText= "编号" });
view.Columns["dataGridviewIndex"].DisplayIndex = 0;
for (int i = 0; i < view.Rows.Count; i++)
{
view.Rows[i].Cells["dataGridviewIndex"].Value = i + 1;
}
}
catch (Exception ex)
{
throw ex;
}
}
我在普通的form里试验过没有任何问题,但是在WeifenLuo继承过来的窗体里就不会显示,但是如果在按钮事件里添加又可以,不知道是什么原因,我觉得不是加载事件顺序不对,因为普通的Form可以实现,哪位高手遇到过这种问题,给予帮助