id = Convert.ToInt16(dgvInfo.Rows[e.RowIndex].Cells[2].Value)具体dgv是什么意思思,看不懂

在C#中 int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells_百度知道
在C#中 int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells
有知道的请给我讲一下吧,谢谢了!
我有更好的答案
LZ一般来说格式应该是: int id=Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].value.ToString())讲解一下意思:Convert.ToInt32(Object Value)是将Value转换为Int类型.SelectedRow[int value]选择dataGridView中的第Value行Cells[int value]需要先指定某一行,获得该行的单元格数据集(C即Cells)。然而指定某一具体单元格就需要指明下标(即Value)。 Value 即获得对应数据.ToString()应该不需要人解释了吧?希望能够 对你有帮助!
采纳率:28%
Convert.ToInt32转换成 INT 类型dataGridView1.SelectedRows[0]
选择 第一 行。再.cells 选择列你这个代码有问题吧…… 没拷贝全 就发上来了。
选择datagrid第一行的列,后面应该是按照索引或者字段来检索的条件,并将值转换为int型。
很简单 意思就是 根据选择gridview行的列值 强制转换成int型然后赋值给 int 的id
你没有copy全获取dataGridView1的第一行的网格数组中的第几个网格中的值。并把其转为int32格式
其他2条回答
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。写了一段C#代码,总是出现问题,是不是dataGridView1.SelectedRows[i].Cells[1].Value.ToString() 有问题_百度知道
写了一段C#代码,总是出现问题,是不是dataGridView1.SelectedRows[i].Cells[1].Value.ToString() 有问题
for (int i = 0; i &dataGridView1.Rows.C i++)
if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true)
{ //添加图书信息SQL语句
sb.Append(&delete...
我有更好的答案
dataGridView1.SelectedRows[i].Cells[1].Value.ToString()改为dataGridView1.Rows[i].Cells[1].Value.ToString()
采纳率:24%
//将for循环改成这样for (int i = 0; i &dataGridView1.SelectedRows.C i++) {
//这个if语句也要改一下
if ((bool)dataGridView1.SelectedRows[i].Cells[0].EditedFormattedValue == true)
{ //添加图书信息SQL语句
sb.Append(&delete
from bookinfo where id='&
+ dataGridView1.SelectedRows[i].Cells[1].Value.ToString() + &';&);}DataGridView中选中的行总是会&=总行数的或者改成下面这样也可以for (int i = 0; i &dataGridView1.Rows.C i++) {
//这个if语句也要改一下
if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true)
{ //添加图书信息SQL语句
sb.Append(&delete
from bookinfo where id='&
+ dataGridView1.Rows[i].Cells[1].Value.ToString() + &';&);}
i的范围是从0到最后1行。也许没有选中全部行,譬如说只选中了1,2行,dataGridView1.SelectedRows,就是1个维数为2的数组,那么i=3时,dataGridView1.SelectedRows[3],这个数组的索引就超出了范围
我觉得可能是你的逻辑有点问题,上面循环的是数据集合的行,但是下面取得是选中的行,如果你没有选择任何行的话,可能就会报这个错误吧。
datagridview默认的是行首选择,也就是说整行都高亮才称为“选中”,重新选择试试。另外,应该先判断选中的行数是否大于0.
其他2条回答
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。private void dgv_CellClick函数为何失效解决方法 - C#当前位置:& &&&private void dgv_CellClick函数为何失效解决方法private void dgv_CellClick函数为何失效解决方法www.MyException.Cn&&网友分享于:&&浏览:3次private void dgv_CellClick函数为何失效程序功能要求:单击dgv中的选择框选择某一行,将其中各单位格的数据赋值给已有变量。程序代码如下:private void dgv_ShowAllReader_CellClick(object sender, DataGridViewCellEventArgs e) &
#region 获取dgv表中被选中修改读者的当前基本信息,赋值给已有相应变量 &
if (e.ColumnIndex == 0) // 选中某一确定读者基本信息 &
update_readerid = Convert.ToInt32(this.dgv_ShowAllReader.Rows[e.RowIndex].Cells[&READER_ID&].Value.ToString()); &
update_readername = this.dgv_ShowAllReader.Rows[e.RowIndex].Cells[&READER_NAME&].Value.ToString(); &
update_studentnum = this.dgv_ShowAllReader.Rows[e.RowIndex].Cells[& STUDENT_NUM&].Value.ToString(); &
update_idcard = this.dgv_ShowAllReader.Rows[e.RowIndex].Cells[&ID_CARD&].Value.ToString(); &
update_readertype = this.dgv_ShowAllReader.Rows[e.RowIndex].Cells[&READER_TYPE_NAME&].Value.ToString(); &
update_readersex = this.dgv_ShowAllReader.Rows[e.RowIndex].Cells[&READER_SEX&].Value.ToString(); &
update_readertell = this.dgv_ShowAllReader.Rows[e.RowIndex].Cells[&READER_TELL&].Value.ToString(); &
update_canborrowmax = Convert.ToInt32(this.dgv_ShowAllReader.Rows[e.RowIndex].Cells[&MAXNUM_CAN_BORROW&].Value.ToString()); &
update_borrowflag = this.dgv_ShowAllReader.Rows[e.RowIndex].Cells[&READER_FLAG_BORROW&].Value.ToString(); &
update_readertext = this.dgv_ShowAllReader.Rows[e.RowIndex].Cells[&READER_INFO&].Value.ToString(); &
#endregion &
}程序运行后,各变量的值无任何改变,为什么?------解决方案--------------------单步一下看看单元格的值有没有取到呗
------解决方案--------------------积分分分分分。。。。。。。。。。
------解决方案-------------------- if (e.ColumnIndex == 0) 这个条件满足么
------解决方案--------------------条件改下试试,if(e.IsSelected==ture)
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有winforms - RowLeave Event - Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function - Stack Overflow
Stack Overflow for Teams
A private, secure home for your team's questions and answers.
to customize your list.
This site uses cookies to deliver our services and to show you relevant ads and job listings.
By using our site, you acknowledge that you have read and understand our
Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.
I have DataGridView Control in windows application.
I load data and bind it to grid using above code.
private void LoadData()
clsData objData = new clsData();
DataTable dtTemp = new System.Data.DataTable();
dtTemp = objData.GetDatatable(" SELECT [ID],[CustomerName],[OrderQty],[Price],[POStatus],[Remarks],[EstdShipDate],[ActualShipDate],[IsShipped]
FROM [tblPO] ");
dgPO.DataSource =
dgPO.DataSource = dtT
where dgPO is DataGrdiView(DGV).
Now i want to update records in DGV when user leaves the row.
for it i have used RowLeave event of DGV.code is here
private void dgPO_RowLeave(object sender, DataGridViewCellEventArgs e)
int POId = Convert.ToString(dgPO.Rows[e.RowIndex].Cells[0].Value) == "" ? 0 : Convert.ToInt32(dgPO.Rows[e.RowIndex].Cells[0].Value);
string CustName = Convert.ToString(dgPO.Rows[e.RowIndex].Cells[1].Value);
int Qty = Convert.ToInt32(dgPO.Rows[e.RowIndex].Cells[2].Value);
decimal Price = Convert.ToDecimal(dgPO.Rows[e.RowIndex].Cells[3].Value);
string Status = Convert.ToString(dgPO.Rows[e.RowIndex].Cells[4].Value);
string Remarks = Convert.ToString(dgPO.Rows[e.RowIndex].Cells[5].Value);
string dtEsdt = Convert.ToDateTime(dgPO.Rows[e.RowIndex].Cells[6].Value).ToString("yyyy-MM-dd");
string dtActl = Convert.ToDateTime(dgPO.Rows[e.RowIndex].Cells[7].Value).ToString("yyyy-MM-dd");
bool Shipped = dgPO.Rows[e.RowIndex].Cells[8].Value == DBNull.Value ? false : Convert.ToBoolean(dgPO.Rows[e.RowIndex].Cells[8].Value);
string strQry = "";
if (POId & 0)
strQry = " UPDATE [tblPO] SET [CustomerName] = '" + PreString(CustName) + "',[OrderQty] = " + Qty + ",[Price] = " + Price + ",[POStatus] = '" + Status + "'";
strQry = strQry + ",[Remarks] = '" + PreString(Remarks) + "',[EstdShipDate] = '" + dtEsdt + "',[ActualShipDate] = '" + dtActl + "',[IsShipped] = '" + Shipped + "'";
strQry = strQry + " WHERE ID =" + POId;
strQry = " INSERT INTO [tblPO] ([CustomerName],[OrderQty],[Price],[POStatus],[Remarks],[EstdShipDate],[ActualShipDate],[IsShipped]) ";
strQry += " VALUES('" + PreString(CustName) + "'," + Qty + "," + Price + ",'" + PreString(Status) + "','" + PreString(Remarks) + "'";
strQry += " ,'" + PreString(dtEsdt) + "','" + PreString(dtActl) + "','" + Shipped + "')";
clsData objData = new clsData();
if (objData.ExecuteQuery(strQry))
LoadData();
When data is updated in DB, I refresh the DGV by calling LoadData method.
At this point, i get an error message like this.
"Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function"
I tried for available solution on SO and MSDN blogs,but they don't work for me
like these
Help needed.
Thanks in advance !!
1,65462140
private void dgPO_RowLeave(object sender, DataGridViewCellEventArgs e)
dataGridView1.EndEdit();
//You code below
Suggestion: The alternative way
Did you try to use
private void dataGridView1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
if (dataGridView1.IsCurrentRowDirty)
//Your code here
5,97651834
use the following check before applying your edit in the "RowLeave" or "EndEdit" method:
public void dgPO_RowLeave(object sender, DataGridViewCellEventArgs e)
if (!dgPO.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected)
//...rest of your code to apply edit below...
This should work with any cell being edited.(the edit-code is not appli Typing Enter would suffice to apply the edit)
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Post as a guest
Post as a guest
By clicking &Post Your Answer&, you acknowledge that you have read our updated ,
and , and that your continued use of the website is subject to these policies.
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled求解.net datagridview[i,e.rowindex].tooltiptext 延长显示时间。
作者:用户
浏览:283 次
不懂如何设置tooltiptext延长显示时间,求大神帮忙。###privatevoidtimer1_Tick(objectsender,EventArgse){toolTip1.Active=fal
问题描述不懂如何设置tooltiptext延长显示时间,求大神帮忙。解决方案解决方案二:privatevoidtimer1_Tick(objectsender,EventArgse){toolTip1.Active=toolTip1.Active=}把timer控件的时间设置长一点试试。解决方案三:privatevoidmyRadGridView1_ToolTipTextNeeded(objectsender,Telerik.WinControls.ToolTipTextNeededEventArgse){ToolTiptoolTip=this.myRadGridView1.ElementTree.ComponentTreeHandler.Behavior.ToolTtoolTip.AutoPopDelay=2000;e.ToolTipText="Hello";}privatevoidradGridView_ToolTipTextNeeded(objectsender,ToolTipTextNeededEventArgse){RadElementelement=senderasRadEif(element==null){}ComponentBehaviorbehavior=(element.ElementTree.ComponentTreeHandlerasIComponentTreeHandler).BPropertyInfotoolTipProperty=typeof(ComponentBehavior).GetProperty("ToolTip",BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.GetProperty);objecttoolTip=toolTipProperty.GetValue(behavior,null);TyperadToolTipType=toolTip.GetType();PropertyInfoautomaticProperty=radToolTipType.GetProperty("AutomaticDelay");PropertyInfoautoPopDelayProperty=radToolTipType.GetProperty("AutoPopDelay");PropertyInfoinitialDelayProperty=radToolTipType.GetProperty("InitialDelay");PropertyInforeshowDelayProperty=radToolTipType.GetProperty("ReshowDelay");intautomaticDelay=;intautoPopDelay=;intinitialDelay=;intreshowDelay=;automaticProperty.SetValue(toolTip,automaticDelay,null);autoPopDelayProperty.SetValue(toolTip,autoPopDelay,null);initialDelayProperty.SetValue(toolTip,initialDelay,null);reshowDelayProperty.SetValue(toolTip,reshowDelay,null);e.ToolTipText="Thisistooltiptext";}解决方案四:上面两种方法试过,不行啊!解决方案五:privatevoiddgvData_RowEnter(objectsender,DataGridViewCellEventArgse){try{for(inti=0;i&dgvData.Rows[e.RowIndex].Cells.Ci++){StringBuildersbder=newStringBuilder();sbder.AppendFormat("行数据基本信息:rnt");for(intj=0;j&dgvData.Rows[e.RowIndex].Cells.Cj++){if(dgvData.Columns[j].Visible){DataGridViewCellcell=dgvData.Rows[e.RowIndex].Cells[j];if(cell.Value.ToString()!=string.Empty){sbder.AppendFormat("{0}:{1}rnt",dgvData.Columns[j].HeaderText,cell.Value.ToString());}}}dgvData[i,e.RowIndex].ToolTipText=sbder.ToString();}}catch{}}要延长这个显示时间解决方案六:lz是想直接修改datagridview的某个参数达到目的,这可能需要你自己编写一个继承类,应当也可以实现,那样以后就方便了!
【云栖快讯】青年们,一起向代码致敬,来寻找第83行吧,云栖社区邀请大神彭蕾、多隆、毕玄、福贝、点评Review你的代码,参与互动者将选取50位精彩回复赠送“向代码致敬”定制T恤1件,最终成为“多隆奖”的小伙伴还将获得由阿里巴巴提供的“多隆奖”荣誉证书和奖杯。&&
弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率
40+云计算产品,6个月免费体验
稳定可靠、可弹性伸缩的在线数据库服务,全球最受欢迎的开源数据库之一
云服务器9.9元/月,大学必备

我要回帖

更多关于 dgv 的文章

 

随机推荐