[RESOLVED] Activate/focus datagrid row.
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:
Friend Sub AddDirectoryItem(ByVal item As cls_icontact)
Dim row As DataRow
If displaytype = ContractDirectoryDisplay.Staff Then
Dim dt As DataTable = CType(dg_contacts.DataSource, DataTable)
For Each row In dt.Rows
If row.RowState = DataRowState.Deleted Then
ElseIf row("id") = item.row("id") Then
MsgBox("User is already assigned !", MsgBoxStyle.Information, "Duplicate Item")
dt.Dispose()
dt = Nothing
Return
End If
Next
dt.Dispose()
dt = Nothing
End If
row = CType(dg_contacts.DataSource, DataTable).NewRow
row.ItemArray = item.row.ItemArray
row("Contract") = CurrentContract.ID
If displaytype <> ContractDirectoryDisplay.Staff Then
row("ContactPhone") = item.row("Phone")
row("ContactFax") = item.row("Fax")
End If
mdtContacts.Rows.Add(row)
MsgBox("New Contact assigned !", MsgBoxStyle.Information, "Assigned")
End Sub
Re: Activate/focus datagrid row.
i do it as follows :
make a custom control that inherits from the datagrid control
place this sub in it like this
VB Code:
public class gridx
inherits datagrid
'Adding scroll to row Functionality
Public Sub ScrollToRow(ByVal row As Integer)
If Not Me.DataSource Is Nothing Then
Me.GridVScrolled(Me, New ScrollEventArgs(Windows.Forms.ScrollEventType.LargeIncrement, row))
End If
End Sub
after that you can call the method like that
VB Code:
gridx1.scrolltorow(10) ' this will scroll to the 10th row
i know building a custom control is overkilling but i am always extending the datagrid as it is very frusterating in vb.net2003
rgds
Re: Activate/focus datagrid row.
Thanks Maged,
Yeah, I had already built a custom datagrid control with lots of added functions / subs already.
Cheers
Bob