BindingNavigator Control with DataGridView

hwdevelop

New member
Joined
Oct 20, 2005
Messages
4
Programming Experience
5-10
Hi All,

I'm trying to make a list using DataGridView with BindingNavigator control using .Net2005 beta. I'm able to work out everything except when i add a new data using the underlying data table and try to change the current Position to a certain value, it always sets it to the last record. The reason i need to do this is because i sorted the datagridview and whenever i added a new data in the underlying data table, it gets sorted right away, hence i need to set the position of BindingNavigator to the new record which always not the last record.

Please help!!!

Thanks in advance!
hw
 
Locate The Added Record

I WOULD THINK THAT YOU WOULD HAVE TO STORE THE RECORD KEY FOR THE RECORD YOU ADDED AND THEN USE A SEARCH SUBROUTINE TO LOCATE THAT SPECIFIC RECORD. SOME FORM OF CELL CHANGE EVENT OR ON ADD NEW EVENT TO SAVE THE RECORD KEY TO A VARIABLE, THEN SOME SEARCH TO LOCATE IT AGAIN IN THE SORTED GRID.
I USE SOMETHING LIKE THIS TO MOVE TO A SELECTED PART RECORD(FROM THE PART DATSET) WHEN A PART NUMBER IS CLICKED ON IN THE PART-DETAIL GRID. HERE IS THAT CODE:

VB.NET:
    Private Sub MoveToPart()
        Dim c As Integer = Me.BindingContext(DsDetail1, "Detail").Count
        If c > 0 Then
            Dim DV As DataView
            Dim I As Integer
            If DetailGrid.Columns("detail part id").Value > 0 Then
                partpointer = DetailGrid.Columns("detail part id").Value
                DV = New DataView(DsPartDetail1.Tables("part"))
                DV.Sort = ("part id")
                I = DV.Find(partpointer)
                Me.BindingContext(DsPartDetail1, "part").Position = I
            End If
        Else
            MsgBox("No Details loaded In Database")
        End If

    End Sub

THE CODE IS A BIT DIFFERENT BECAUSE I USE A 3RD PARTY DATAGRID (COMPONENT ONE), BUT YOU SHOULD GET THE IDEA.
HOPE THIS HELPS GET YOU GOING.
 
Back
Top