Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

navigating to record on form from another form

vb.net 2008
binding controls...binding navigators
form1
form2

I have a form1 : That has a datagrdview.

I have a command button on that form1  that opens form2...and then is going to a record on form2

based on the following:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frmForm1.Dispose()
        frmForm2.Show()
 frmForm1.TblMainDataBindingSource.Position = BindingNavigatorPositionItem.Text - 1
end sub


Problem:
The record in form2 is going to a record based on the position of the record I have clicked  in the Datagridview in form1.

What I need:
There is a ColumnHeader ("MainTableId") in the datagridview on form1 that shows the id number that corresponds to the id in form2..

I want to go to the record in form2 based on the "MainTableId" number  NOT based on the position in the datatgridview...because people will sort the datagridview.. and the positions will be thrown off..

Thanks\
fordraiders




0
Fordraiders
Asked:
Fordraiders
  • 4
1 Solution
 
kdwoodCommented:

How about something like this:


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Form2.Show()

        ' Search the binding source on form 2 for the "MainTableID" value in the ID field.  Store the index location
        ' where the record was found.

        Dim myIDX As Integer = Form2.YourBindingSource.Find("ID", YourDataGridView.Item("MainTableId",  YourDataGridView.CurrentRow.Index).Value)

       ' Now position the binding source on form 2 to the index of the located record

        Form2.YourBindingSource.Position = myIDX

    End Sub

Open in new window

0
 
FordraidersAuthor Commented:
I'm to stay away from.position...because it involves an index..position...

I was hoping to just get the value from colunm1 and wahtever row has been selected and use that value to find taht "ID" record in the form2 ...

But your suggestion did not work...

Thanks
fordraiders
0
 
FordraidersAuthor Commented:
error,
YourDataGridView.Item("MainTableId",    <<<<---- no valid column name exists///
0
 
FordraidersAuthor Commented:
sorry, My bad...forget to assign form2  ...

works great !
0
 
FordraidersAuthor Commented:
Thanks works great
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now