private void dgvData_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
string Area = this.dgvData.Rows[e.RowIndex].Cells["Area"].Value.ToString(); //获取区域列值
string Locate = this.dgvData.Rows[e.RowIndex].Cells["Location"].Value.ToString(); //获取位置列值 if (Area != "" && Locate != "") //判断都不为空
{
bool isNo = false; //用于判断该区域和位置是否存在
for (int i = 0; i < this.dgvData.Rows.Count - 2; i++)
{
if (Area == dgvData.Rows[i].Cells["Area"].Value.ToString() && Locate == dgvData.Rows[i].Cells["Location"].Value.ToString()) //判断该区域和位置是否已经存在
{
isNo = true; //已存在
break;
}
} if (isNo == true) //如果存在可选择是否覆盖
{
if (MessageBox.Show("该区域中的位置已经存在!是否覆盖?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1) == DialogResult.OK)
{
for (int i = 0; i < this.dgvData.Rows.Count; i++)
{
if (this.dgvData.Rows[i].Cells["Area"].Value.ToString() == Area && this.dgvData.Rows[i].Cells["Location"].Value.ToString() == Locate)
{
// this.dgvData.Rows[i + 2].Selected = true;
this.dgvData.Rows.RemoveAt(i); //存在,移除已经存在的 break;
}
}
}
else
{
this.dgvData.Rows.RemoveAt(e.RowIndex); //选择不覆盖则移除添加的行
}
}
}
}当添加一条已经存在的。
选择不覆盖,则会把当前的移除。
选择覆盖,会把已经存在的移除。但是当前添加的也没有了???
这是什么情况?? 求大侠帮忙DataGridView
{
string Area = this.dgvData.Rows[e.RowIndex].Cells["Area"].Value.ToString(); //获取区域列值
string Locate = this.dgvData.Rows[e.RowIndex].Cells["Location"].Value.ToString(); //获取位置列值 if (Area != "" && Locate != "") //判断都不为空
{
bool isNo = false; //用于判断该区域和位置是否存在
for (int i = 0; i < this.dgvData.Rows.Count - 2; i++)
{
if (Area == dgvData.Rows[i].Cells["Area"].Value.ToString() && Locate == dgvData.Rows[i].Cells["Location"].Value.ToString()) //判断该区域和位置是否已经存在
{
isNo = true; //已存在
break;
}
} if (isNo == true) //如果存在可选择是否覆盖
{
if (MessageBox.Show("该区域中的位置已经存在!是否覆盖?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1) == DialogResult.OK)
{
for (int i = 0; i < this.dgvData.Rows.Count; i++)
{
if (this.dgvData.Rows[i].Cells["Area"].Value.ToString() == Area && this.dgvData.Rows[i].Cells["Location"].Value.ToString() == Locate)
{
// this.dgvData.Rows[i + 2].Selected = true;
this.dgvData.Rows.RemoveAt(i); //存在,移除已经存在的 break;
}
}
}
else
{
this.dgvData.Rows.RemoveAt(e.RowIndex); //选择不覆盖则移除添加的行
}
}
}
}当添加一条已经存在的。
选择不覆盖,则会把当前的移除。
选择覆盖,会把已经存在的移除。但是当前添加的也没有了???
这是什么情况?? 求大侠帮忙DataGridView
解决方案 »
- 接口和抽象类的作用
- 将原数组向后推移两位
- vs2005 treeview如何绑定到数据库中表的内容
- 在VS2005中载入项目(SLN文件),怎么打不开代码窗口啊?
- 特急,CSDN上。NET高手呢?
- 输入两个整数n和m,从数列1,2,3.......n 中 随意取几个数,使其和等于 m ,要求将其中所有的可能组合列出来.编程求解。
- 在C#中如何强行终止DOS应用程序
- 那位有磁卡读写器的类库,支持.net的,请介绍一下~
- C#控制台应用程序中的<清屏>语句是???
- 请问C#中怎么拷贝一个文件夹包括子目录?
- 多个checkBox控件逻辑关系问题,请教下。。
- VS coded ui test 编码的UI测试 导致程序内存溢出
删除要倒着来
我用的是
SqlDataAdapter adp = new SqlDataAdapter("select ShelfID,Area,GroupGoods,Location,SegmentNum from dbo.ShelfInformation", DBHelp.Connection);
SqlCommandBuilder builder = new SqlCommandBuilder(adp);
adp.Fill(dt);
adp.Update(dt);
我用的是
SqlDataAdapter adp = new SqlDataAdapter("select ShelfID,Area,GroupGoods,Location,SegmentNum from dbo.ShelfInformation", DBHelp.Connection);
SqlCommandBuilder builder = new SqlCommandBuilder(adp);
adp.Fill(dt);
adp.Update(dt);
你在判断的时候 把 dgv.DataSource as DATABALE();
DataTable dtCostName = (dgvFeeType.DataSource as DataTable).Copy(); DataView dv = new DataView(dtCostName);
if (dv.Count != dv.ToTable(true, "CostName").Rows.Count)
好好研究一下