none
Datagridview bindingnavigator on Detail form

    Question

  • Hi Friends,

    Please  seeking for help  as I have datagridview on one form and want to bind it to bindingnavigator  which is located to another child forms is it possible  

    


    asad

    Wednesday, March 22, 2017 6:16 AM

All replies

  • Hello,

    Here are some basics which may not fully match up with what you have but should get you rolling.

    I added a BindingNavigator to a child form, add TextBoxes for fields to work with (in the code sample below only one TextBox is done).

    I have a BindingNavigator on the main form named ProductsBindingNavigator and a BindingSource named ProductsBindingSource. They are linked up as shown below along with doing a AddHandler for the save operation.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
        Dim f As New Form2
    
        f.BindingNavigator1.BindingSource = ProductsBindingSource
        f.ProductsBindingNavigatorSaveItem.Image = ProductsBindingNavigatorSaveItem.Image
    
        AddHandler f.ProductsBindingNavigatorSaveItem.Click,
            AddressOf ProductsBindingNavigatorSaveItem_Click
    
        f.TextBox1.DataBindings.Add("Text", ProductsBindingSource, "ProductName")
        Try
            f.ShowDialog()
        Finally
            f.Dispose()
        End Try
    
    End Sub

    I see you don't have a BindingNavigator on the main form so either place one there and wire it up then hide it or work around it by wiring up the child form's BindingNavigator as it would had been if dropped on the form.

    See animated screenshot

    https://1drv.ms/i/s!AtGAgKKpqdWjiDLJChLCbgSjdNjG


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, March 22, 2017 10:24 AM
    Moderator
  • thank you for reply I am using following code to moving forward  but its not working properly I means not returning  current highlighted recorded 

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim xcount As Integer
            xcount = credit_grid.Rows.Count
            If credit_grid.Rows.Count > 0 Then

                Dim counter As Integer = credit_grid.CurrentRow.Index + 1
                Dim nextRow As DataGridViewRow
                MsgBox(credit_grid.CurrentRow.Index.ToString)

                If counter >= xcount Then

                    ' nextRow = credit_grid.Rows(credit_grid.Rows.Count + 1)
                    nextRow = credit_grid.Rows(0)
                Else

                    nextRow = credit_grid.Rows(counter)

                End If

                credit_grid.CurrentCell = nextRow.Cells(0)

                nextRow.Selected = True


            End If
        End Sub


    asad

    Tuesday, April 11, 2017 7:12 AM
  • Did you not try what I recommended?

    A BindingSource has method to move forward and backwards as per the following methods

    Your data is set to the BindingSource.DataSource then the BindingSource is set to the DataSource of the DataGridView.

    Let's say you are on the first row of the DataGridView and execute BindingSource1.MoveNext, now the second row of the DataGridView is the current row. If you were on the last row and did BindingSource1.MoveNext nothing will happen but BindingSource1.MovePrevious move back one row.

    In the above case BindingSource1 is a name I gave to a BindingSource component, you can name it whatever you want.

    In short, using a BindingSource has much less code then rolling your own method to move up and down in a DataGridView. Of course if you are not using the DataSource of a DataGridView this will not work but it's a wise idea to load data using the DataSource and can be done easily depending on where the data is coming from. You could use a class or a DataTable for instance to load the BindingSource as described above.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, April 11, 2017 11:02 AM
    Moderator