如何在运行时更改当前单元格 [英] how to change current cell at run time
问题描述
我的表单只有一个带有5列的datagridview控件
代码在这里
公共 类 Form2
私有 Sub DataGridView1_CellValidating( ByVal 发件人目标 对象,
ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs)
句柄 DataGridView1.CellValidating
如果 e.ColumnIndex = 1 然后
DataGridView1.CurrentCell = 新建 DataGridViewCell( 1 , 4 跨度>)
结束 如果
结束 子
结束 类
我想将当前单元格更改为多孔单元格
如果我给出以下命令:
myGrid.CurrentCell = 新建 DataGridViewCell( 1 , myGrid.CurrentCell = DataGridViewCell( 1 , 3 )
现在我收到此错误消息:
DataGridViewCell是一种类型,不能用作表达式
如果我这样更改命令:
myGrid.CurrentCell = 我 .myGrid( 1 , 3 )
我收到此错误:
xxxx.exe中发生了类型为"System.StackOverflowException"的未处理的异常
帮助我更改当前的单元格.
thomas
tonymon987654写道:如果我这样更改命令: br/> myGrid.CurrentCell = Me.myGrid(1,3)
我收到此错误:
xxxx.exe中发生了类型为"System.StackOverflowException"的未处理的异常
好吧,这是更改当前所选单元格焦点的正确语法.看起来您是从CellValidating
事件执行此操作的.当前单元格的焦点已更改后,将触发该事件;如果您要从此处更改当前单元格,则会创建一个无限循环-这将解释StackOverflowException
.
尝试改变另一个事件的焦点,例如CellValidated
.
要添加答案,您应该买一本书并尝试阅读,而不用猜测随机的事物.找到您想做的事.
嗨
您可以通过以下代码设置datagridview currentcell属性
在vb.net
myGrid.CurrentCell = this.myGrid(1,3);
希望对您有帮助
问候
库马兰
hi
my form having only one datagridview control with 5 column
the code is here
Public Class Form2
Private Sub DataGridView1_CellValidating(ByVal sender As Object,
ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs)
Handles DataGridView1.CellValidating
If e.ColumnIndex = 1 Then
DataGridView1.CurrentCell = New DataGridViewCell(1, 4)
End If
End Sub
End Class
I want change current cell to a prticular cell
if i give this command:
myGrid.CurrentCell = New DataGridViewCell(1, 3)
i got error message :
New cannot be used a class that is declared mustinherit
i change the command like this:
myGrid.CurrentCell = DataGridViewCell(1, 3)
now i get this error message:
DataGridViewCell is a type and cannot be used as an expression
if i change the command like this:
myGrid.CurrentCell = Me.myGrid(1, 3)
iam getting this error:
An unhandled exception of type ''System.StackOverflowException'' occurred in xxxx.exe
help me to change my current cell.
thomas
tonymon987654 wrote:if i change the command like this:
myGrid.CurrentCell = Me.myGrid(1, 3)
iam getting this error:
An unhandled exception of type ''System.StackOverflowException'' occurred in xxxx.exe
Well, it''s the right syntax to change the focus of the currently selected cell. Looks like you doing this from theCellValidating
-event. That event is triggered after the focus of the current cell has changed; if you''re changing the current cell from there, you''d be creating an infinite loop - and that would explain theStackOverflowException
.
Try to change the focus from another event, likeCellValidated
.
To add to the answer you were given, you should buy a book and try reading it instead of guessing random things to try to find what you want to do.
Hi
you may set the datagridview currentcell property by following code
in vb.net
myGrid.CurrentCell = this.myGrid(1, 3);
hope this helps
regards
Kumaran
这篇关于如何在运行时更改当前单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!