Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
my form having only one datagridview control with 5 column
the code is here

VB
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:
VB
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:
VB
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:
VB
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
Posted
Updated 8-Feb-10 13:57pm
v5

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 the CellValidating-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 the StackOverflowException.

Try to change the focus from another event, like CellValidated.
 
Share this answer
 
v2
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.
 
Share this answer
 
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
 
Share this answer
 
Try this:
DataGridView1.Rows(1).Cells(3).value
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900