Solved

navigating to record on form from another form

Posted on 2011-02-25
5
327 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
Comment Utility

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
Comment Utility
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
Comment Utility
error,
YourDataGridView.Item("MainTableId",    <<<<---- no valid column name exists///
0
 
LVL 3

Author Comment

by:fordraiders
Comment Utility
sorry, My bad...forget to assign form2  ...

works great !
0
 
LVL 3

Author Closing Comment

by:fordraiders
Comment Utility
Thanks works great
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

9 Experts available now in Live!

Get 1:1 Help Now