focus on row
-
What I want to do: I have a listview, when the user clicks on a row and presses an edit button, a dialog is shown and the user can change the row in the dataset. The dialog contains several databound edit controls. problem: The dialog should focus on the right row. most of the time, this is correct. But sometimes it is not. Not sure why, but it happens when I add, remove rows from the dataset or sort the data. Is this approach correct? what should be the problem? my code:
Private Sub btnWICustomerEdit_Click(...) ... Dim key As Integer = getkey() 'create form Dim EditData As frmEditDataActivities = New frmEditDataActivities(...) Dim rowIndex As Integer = **dsCustomers.Tables(0).DefaultView.Find**(Key) If rowIndex = -1 Then Return End If 'focus on the right row EditData.SetFocusRow(rowIndex, dsCustomers) EditData.ShowDialog() 'do update, save changes End Sub 'a member from the dialog class Public Sub SetFocusRow(ByVal rowIndex As Integer, ByRef dsCustomers As dsCustomers) **Dim cm As CurrencyManager cm = CType(Me.BindingContext(dsCustomers, dsCustomers.Tables(0).TableName), CurrencyManager) cm.Position = rowIndex** End Sub