?
Solved

navigating to record on form from another form

Posted on 2011-02-25
5
Medium Priority
?
356 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

718 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