Solved

navigating to record on form from another form

Posted on 2011-02-25
5
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

736 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