Quantcast
Viewing all articles
Browse latest Browse all 27069

VS 2010 VB.NET 2010 Winforms Datagridview Cursor to Focused Cell

I am trying to get the cursor to move to the focused datagridview cell after a record is edited.

The dgv has 2 visible columns, first column is an image (small icon) and the 2nd col titled “Titles”. As each cell in the “Titles” column is selected either by mouse click or keyboard up/down arrow keys, the numerous textboxes on the WinForm are populated with the corresponding data for the selected record. The dg is bound to a dataset(ds0) pulled from a MySQL db.

When a record is edited, it is saved back to the db and the dataset re-read with the updated db records. The problem is, even though I can set the focused dgv cell to the record that was last edited and it displays in the textboxes, how can I get the cursor to be at the same focused cell in the dgv?

For example, the dgv is displaying an arbitrary number of cells, 33 in my case as default, the record that was edited is say 455 (dgv index number), I want the cursor to go back to that particular cell after the re-read. The focused record is displaying in the textboxes correctly, just need the cursor position to line up.

I have tried using these but none get the cursor into the correct position:

DataGridView1.CurrentCell = DataGridView1.CurrentRow.Cells("Title")
DataGridView1.Rows(i).Selected = True
DataGridView1.CurrentCell = DataGridView1.Item("Title", i)
DataGridView1.CurrentCell = DataGridView1.Rows(i).Cells(1)
Any help appreciated....



da0.SelectCommand = sql
conn.Open()
da0.Fill(ds0, "titles")
conn.Close()
Try
ds0.Tables("titles").DefaultView.Sort = "nvcSortTitle ASC"
DataGridView1.DataSource = ds0.Tables("titles")
Catch ex As Exception
MsgBox(ex.Message)
End Try


MaxRows = ds0.Tables("titles").Rows.Count - 1
txtTotalMovies.Text = MaxRows
If CurrentRecord = 0 Then
CurrentRecord = 1
End If
' -----Display 1st record from datagrid on startup
Dim i As Integer = 0
'DataGridView1.CurrentCell = DataGridView1.CurrentRow.Cells("Title")
'DataGridView1.Rows(i).Selected = True
'DataGridView1.CurrentCell = DataGridView1.Item("Title", i)
'DataGridView1.CurrentCell = DataGridView1.Rows(i).Cells(1)
ReadDataGrid1(i)
Return ds0

Private Sub ReadDataGrid1(ByVal i As Integer)


If i > -1 And i <= DataGridView1.Rows.Count.ToString() - 1 Then
' -----Remember the current record for editing purposes
CurrentRecord = DataGridView1.Item(0, i).Value


Me.txtnvcLocalTitle.Text = DataGridView1.Item(1, i).Value
Me.txtntxDescription.Text = DataGridView1.Item(3, i).Value
Me.txtintProductionYear.Text = DataGridView1.Item(4, i).Value
Me.txtintRuntime.Text = DataGridView1.Item(5, i).Value
Me.txtnvcUPC.Text = DataGridView1.Item(9, i).Value
Me.txtnvcSortTitle.Text = DataGridView1.Item(14, i).Value
Me.txtnvcAspectRatio.Text = DataGridView1.Item(16, i).Value
Me.txtdatRecordChanged.Text = DataGridView1.Item(18, i).Value
Me.txtnvcIMDB.Text = DataGridView1.Item(19, i).Value
Me.txtnvcMediaType.Text = DataGridView1.Item(20, i).Value
Me.cmbFormat.Text = DataGridView1.Item(22, i).Value
Me.txtdecFileSize.Text = DataGridView1.Item(23, i).Value & " GB"
Me.txtnvcRegion.Text = DataGridView1.Item(24, i).Value
Me.txtnvcLhdd.Text = DataGridView1.Item(29, i).Value
Me.txtnvcLocation.Text = DataGridView1.Item(31, i).Value
Me.txtComment.Text = DataGridView1.Item(32, i).Value
Me.txtnvcTitleFileName.Text = DataGridView1.Item(33, i).Value

Viewing all articles
Browse latest Browse all 27069

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>