Solved

navigating to record on form from another form

Posted on 2011-02-25
5
329 Views
Last Modified: 2012-08-13
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
Comment
Question by:fordraiders
  • 4
5 Comments
 
LVL 10

Accepted Solution

by:
kdwood earned 500 total points
ID: 34983956

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
 
LVL 3

Author Comment

by:fordraiders
ID: 34985531
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
 
LVL 3

Author Comment

by:fordraiders
ID: 34985536
error,
YourDataGridView.Item("MainTableId",    <<<<---- no valid column name exists///
0
 
LVL 3

Author Comment

by:fordraiders
ID: 34985571
sorry, My bad...forget to assign form2  ...

works great !
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 34985575
Thanks works great
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now