2013-01-14 102 views
0

我试图让在GridView的编辑的单元格的单元格值。有人可以用我的语法来帮助我吗?此代码适用于在GridView的第一行:gridview的编辑细胞VB

Dim Q As Integer = e.NewValues(e.RowIndex) 

,但我接受和错误,如果我更新线2 ... ...我的变量是““:

Index was out of range. Must be non-negative and less than the size of the collection. 

将打印出正确的行当前正在编辑:

System.Diagnostics.Debug.Print(e.RowIndex) 

我甚至想直接获取单元格的值:

Dim Qoh As Integer = CInt(gvInventory.Rows(e.RowIndex).Cells(2).Text) 

有了一个错误:

Conversion from string "" to type 'Integer' is not valid. 
+0

这是因为它是空的......你想什么...设置断点转换,看看你会得到什么了变量...使用CTYPE投作为一个整数太 – Codexer

+0

它不应该是空的。它有一个价值。 – iDev

+0

变化。文本到您的变量 – Codexer

回答

0

此代码工作了我的问题:

Dim Qoh As Integer = CInt(e.NewValues(0)) 

我想这是因为这是唯一的在网格中的可编辑单元格。

+0

只有单元格可在网格中编辑?我很困惑,除非你因为某种原因设置了这个。但我很高兴你的问题得到解决。 – Codexer

0
Dim Qoh As Integer = CType(gvInventory.SelectedRows(0).Cells(2).Text, Integer) 

试试这个...

+0

我这样做,它仍然错误:昏暗的库存量为整数= CTYPE(gvInventory.Rows(e.RowIndex).Cells(2)。文本,整数)从字符串“”到转换键入'整数'无效。 – iDev

+0

我正在RowUpdating事件中执行此操作。它似乎并没有抓住更新后的值,甚至没有抓住单元中的旧值。 – iDev