我在Load事件里面这么写
projectinfo = PushersManagement.GetPusherByFunction(FunctionsManagement.GetIdByName("Project"));
for (int i = 0; i < this.projectinfo.Count; i++)
{
int index = this.dgvProject.Rows.Add();
this.dgvProject.Rows[index].Cells["cmPid"].Value = this.projectinfo[i].Pid;
this.dgvProject.Rows[index].Cells["cmProject"].Value = this.projectinfo[i].PfItem;
this.dgvProject.Rows[index].Cells["cmDeadline"].Value = this.projectinfo[i].EndTime;
}绑定数据之后,在RowValidated里写了如下代码
private void dgvProject_RowValidated(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex > 0)
{
Pushers pf = new Pushers();
//新增
pf.Cid.Cid = 1;
pf.PfItem = this.dgvProject.Rows[e.RowIndex].Cells["cmProject"].Value.ToString();
pf.PfContent = "";
pf.PfLocation.LocationId = 1;
pf.PfTag.Tid = 1;
pf.PfPriority.Pid = 1;
pf.PfBeginTime = null;
pf.PfEndTime = Convert.ToDateTime(this.dgvProject.Rows[e.RowIndex].Cells["cmDeadline"].Value);
pf.PfCompletedTime = null;
pf.PfFunction.Fid = FunctionsManagement.GetIdByName("Project");
pf.pfRole.Rid = 1;
PushersManagement.AddPushers(pf);
}
}
现在这么写出现的问题就,我每次点击一行的时候,他都会新增一条数据,我想判断如果有数据并改变了的话,那么就更新数据,没改变的话,就不做任何操作。如果点击的是一个空行,并写了相应的内容之后就新增,没写的话也是不做任何操作。。
现在不知道怎么判断。
求高人指点。。
projectinfo = PushersManagement.GetPusherByFunction(FunctionsManagement.GetIdByName("Project"));
for (int i = 0; i < this.projectinfo.Count; i++)
{
int index = this.dgvProject.Rows.Add();
this.dgvProject.Rows[index].Cells["cmPid"].Value = this.projectinfo[i].Pid;
this.dgvProject.Rows[index].Cells["cmProject"].Value = this.projectinfo[i].PfItem;
this.dgvProject.Rows[index].Cells["cmDeadline"].Value = this.projectinfo[i].EndTime;
}绑定数据之后,在RowValidated里写了如下代码
private void dgvProject_RowValidated(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex > 0)
{
Pushers pf = new Pushers();
//新增
pf.Cid.Cid = 1;
pf.PfItem = this.dgvProject.Rows[e.RowIndex].Cells["cmProject"].Value.ToString();
pf.PfContent = "";
pf.PfLocation.LocationId = 1;
pf.PfTag.Tid = 1;
pf.PfPriority.Pid = 1;
pf.PfBeginTime = null;
pf.PfEndTime = Convert.ToDateTime(this.dgvProject.Rows[e.RowIndex].Cells["cmDeadline"].Value);
pf.PfCompletedTime = null;
pf.PfFunction.Fid = FunctionsManagement.GetIdByName("Project");
pf.pfRole.Rid = 1;
PushersManagement.AddPushers(pf);
}
}
现在这么写出现的问题就,我每次点击一行的时候,他都会新增一条数据,我想判断如果有数据并改变了的话,那么就更新数据,没改变的话,就不做任何操作。如果点击的是一个空行,并写了相应的内容之后就新增,没写的话也是不做任何操作。。
现在不知道怎么判断。
求高人指点。。
DataGridView绑定数据之后,可以实现自动新增一行(已实现)
单机任意一行的时候
如果该行有数据并改变了的话,那么就更新数据,没改变的话,就不做任何操作。
如果点击的是一个空行,并写了相应的内容之后就新增,没写的话也是不做任何操作。。
现在我的问题是 只要我点击一行就会新增
不知道怎么判断是空行还是有数据
如果有数据的话,不知道怎么判断是否更新
如果没数据,鼠标移除的时候,不知道怎么判断是否新写入数据