datagridview索引以及双击事件 datagridview索引 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 子窗体代码 private void btnOK_Click(object sender, EventArgs e) { string mysql = ""; mysql = "update YWPOI set NAME='"+txtNAME.Text+"'"; OleDbDataAdapter dataAdapter = new OleDbDataAdapter(mysql, DBHelper.conn2); this.DialogResult = DialogResult.OK; } private void button1_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } objectid是主键问题,双击一行,没有弹出子窗口,无论选中哪一行,我点击button3时,都提示“请先选择一条记录”。 if (e.ColumnIndex == 0)//这里决定了你必须双击第一列才行,双击其他列就直接退出方法了if (dgv.Rows[e.RowIndex].Cells[1].Value != null)这里决定了你第二列必须有值,如果是null,那么就退出方法了这种问题,自己断点调试一下应该很容易能发现才对 frm.ShowDialog();//显示子窗口 //给输出参数赋值默认值 outNAME = NAME; //判断是否进行修改数据 myresult = frm.DialogResult;这里,应该myresult=frm.ShowDialog();ShowDialog方法本身有返回值,返回值类型就是DialogResult,不用费2遍事 if (selectrowindex < 0)这里,你判断的是个全局变量啊,你确定它有被重新赋值过?为什么不用gdv.SelectedRows来判断呢 dgv.Rows[e.RowIndex].Cells[1].Value 取的是 SHAPE的值,当然是空了。 条件根本不成立。 改成dgv.Rows[e.RowIndex].Cells[3].Value 点击button3提示超出索引 楼主何必拐这么大的弯呢。DataGridView本身就有提供当前行的属性呀dataGridView1.CurrentRow 是当前行dataGridView1.CurrentCell 当前选中的单元格dataGridView1.CurrentCell.OwenRow 当前单元格所有的行private void button3_Click_1(object sender, EventArgs e) { if (dataGridView1.CurrentRow==null) { MessageBox.Show("请先选择一条记录"); return; } if (dataGridView1.CurrentRow.Cells[1].Value != null) { //输入参数 string NAME =dataGridView1.CurrentRow.Cells[3].Value.ToString(); //输出参数 string outNAME; //返回弹出窗口关闭状态 DialogResult myresult; this.ShowDialogForm(NAME, out outNAME, out myresult); //如果修改了数据,把当前datagridview内容的对应值进行修改 if (myresult == DialogResult.OK) { dataGridView1.CurrentRow.Cells[3].Value = outNAME; } } } //获取当前选择的目标 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { selectrowindex = e.RowIndex; }接上面的 这个可以不用了。 改成dgv.Rows[e.RowIndex].Cells[3].Value 点击button3提示超出索引button3里哪来的e.RowIndex C# ListView 滚动条大小问题 C# 操作注册表 水晶报表横向打印问题 关于“强名称”的问题。。。 DataGrid绑定标题 怎么让搜索的关键字变色 Debug这个怎么用!!! 水晶报表初级问题:报表只显示字段名称,却没有数据显示! 100高分觅高手请教c#winform中怎么用Zlib1.2.3进行解压 组件得动态热插拔问题!!! 来!五一放假了,给大家一份端口扫描的源码分享一下! c# 数据保存到oracel中问题 关于wsdl?动态带包头调用的问题???
{
string mysql = "";
mysql = "update YWPOI set NAME='"+txtNAME.Text+"'";
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(mysql, DBHelper.conn2);
this.DialogResult = DialogResult.OK; } private void button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
objectid是主键问题,双击一行,没有弹出子窗口,无论选中哪一行,我点击button3时,都提示“请先选择一条记录”。
if (dgv.Rows[e.RowIndex].Cells[1].Value != null)这里决定了你第二列必须有值,如果是null,那么就退出方法了这种问题,自己断点调试一下应该很容易能发现才对
//给输出参数赋值默认值
outNAME = NAME;
//判断是否进行修改数据
myresult = frm.DialogResult;
这里,应该
myresult=frm.ShowDialog();
ShowDialog方法本身有返回值,返回值类型就是DialogResult,不用费2遍事
这里,你判断的是个全局变量啊,你确定它有被重新赋值过?为什么不用gdv.SelectedRows来判断呢
楼主何必拐这么大的弯呢。DataGridView本身就有提供当前行的属性呀dataGridView1.CurrentRow 是当前行
dataGridView1.CurrentCell 当前选中的单元格
dataGridView1.CurrentCell.OwenRow 当前单元格所有的行
private void button3_Click_1(object sender, EventArgs e)
{
if (dataGridView1.CurrentRow==null)
{
MessageBox.Show("请先选择一条记录");
return;
}
if (dataGridView1.CurrentRow.Cells[1].Value != null)
{
//输入参数
string NAME =dataGridView1.CurrentRow.Cells[3].Value.ToString();
//输出参数
string outNAME;
//返回弹出窗口关闭状态
DialogResult myresult;
this.ShowDialogForm(NAME, out outNAME, out myresult);
//如果修改了数据,把当前datagridview内容的对应值进行修改
if (myresult == DialogResult.OK)
{
dataGridView1.CurrentRow.Cells[3].Value = outNAME;
}
}
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
selectrowindex = e.RowIndex;
}接上面的 这个可以不用了。
button3里哪来的e.RowIndex