|
-
Jun 24th, 2010, 09:32 AM
#1
Thread Starter
Addicted Member
[RESOLVED] How to select a cell in datagridview?
I have a dgv with 14 columns.
If i'm in dgv.item(8,0) in edit mode
What code can i use to jump to (12,0) and also enter editmode.
I call it editmode, dont know what the actual term is . Its the state where you can enter a value into that cell
-
Jun 24th, 2010, 10:25 AM
#2
Frenzied Member
Re: How to select a cell in datagridview?
Datagridview.CurrentCell = Datagridview.Rows(12).Cells(0)
Justin
-
Jun 25th, 2010, 02:31 AM
#3
Thread Starter
Addicted Member
Re: How to select a cell in datagridview?
The code you provided only selects the cell, but doesn't enter "editmode". I still have to click the cell before I can enter any data into that cell.
2nd problem I encountered was this error.

Any Ideas?
-
Jun 25th, 2010, 02:44 AM
#4
Re: How to select a cell in datagridview?
Why is your code in the CellLeave event handler? Also, this:
Code:
Datagridview.Rows(12).Cells(0)
is more simply done like this:
Code:
Datagridview(0, 12)
-
Jun 25th, 2010, 02:56 AM
#5
Thread Starter
Addicted Member
Re: How to select a cell in datagridview?
This is only my test project. In my main project it works like this:
The first column is the important one. After the user selected a value from the DatagridviewComboBoxColumn in column(0) it loads certain data from a table in the database. Then it defaults the values of some of the other columns.
99.99% of the time the values that have been defaulted wont need changing, so my goal is to skip the defaulted columns and jump directly into the important ones. This will make it easier for the user to capture data.
-
Jun 25th, 2010, 04:16 AM
#6
Thread Starter
Addicted Member
Re: How to select a cell in datagridview?
I found a way.
Here it is
vb Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load intActivate = 1 End Sub Dim intActivate As Integer = 0 Dim WishedForCell As DataGridViewCell = Nothing Private Sub dgvPrice_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellValueChanged If e.ColumnIndex = 0 Then If intActivate = 1 Then Static RedirectingCell As Boolean = False If Not RedirectingCell Then If e.ColumnIndex = 0 Then RedirectingCell = True WishedForCell = dgv.Item(2, e.RowIndex) End If End If RedirectingCell = False End If End If End Sub Private Sub dgvPrice_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgv.KeyUp If WishedForCell IsNot Nothing Then Me.dgv.CurrentCell = WishedForCell WishedForCell = Nothing End If End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|