Guys,

In the sub below I am adding a new row to a datagrid on screen. Instead of showing the msgbox at the end of the code, I would like to ensure that the row just added has focus and is visible on screen. This row is always added at the bottom, and sometimes this is off screen if I already have 20 rows in the grid. How can I ensure that the row added is focused and scrolled to if required ?

Thanks
Bob



VB Code:
  1. Friend Sub AddDirectoryItem(ByVal item As cls_icontact)
  2.         Dim row As DataRow
  3.         If displaytype = ContractDirectoryDisplay.Staff Then
  4.             Dim dt As DataTable = CType(dg_contacts.DataSource, DataTable)
  5.             For Each row In dt.Rows
  6.                 If row.RowState = DataRowState.Deleted Then
  7.                 ElseIf row("id") = item.row("id") Then
  8.                     MsgBox("User is already assigned !", MsgBoxStyle.Information, "Duplicate Item")
  9.                     dt.Dispose()
  10.                     dt = Nothing
  11.                     Return
  12.                 End If
  13.             Next
  14.             dt.Dispose()
  15.             dt = Nothing
  16.         End If
  17.         row = CType(dg_contacts.DataSource, DataTable).NewRow
  18.         row.ItemArray = item.row.ItemArray
  19.         row("Contract") = CurrentContract.ID
  20.         If displaytype <> ContractDirectoryDisplay.Staff Then
  21.             row("ContactPhone") = item.row("Phone")
  22.             row("ContactFax") = item.row("Fax")
  23.         End If
  24.         mdtContacts.Rows.Add(row)
  25.         MsgBox("New Contact assigned !", MsgBoxStyle.Information, "Assigned")
  26.     End Sub