Navigating Datagrid from Another Form

Joined
Sep 15, 2005
Messages
6
Programming Experience
1-3
I have a datagrid on one form, for example is may look like below

ID NAME COMPANY
1 Steve Microsoft
2 Bill Apple
3 John Google

i have another form that pops up to deliver more detail on each row,
what i am looking for is away to navigate through the records of the data grid from the popup form.

This is very similar to the 'Get Info' form of iTunes if you have used it that may help if not then, the form has next and previous buttons that when clicked go to the next row of the datagrid and present relevant detail in the popup from.

I have tried...

Creating a public sub on Main Form and calling it from the popup form:

visual basic code:Public Sub NextRecord()

Dim frmPopUp As frmPopUp = New frmPopUp
Dim intID As Integer

intID = DataGrid1.Item(DataGrid1.CurrentRowIndex+1, 0)
frmPopUp.SubToPresentDetail(intID)

end sub​

On Pop Up form:

visual basic code:Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Dim frmMainForm As frmMainForm = New frmMainForm
frmMainForm.NextRecord()
End Sub​


with this method i get the error:

System.InvalidOperationException: Data cannot be read from a DataGrid which is not bound to a DataTable.
at System.Windows.Forms.DataGrid.EnsureBound()
at System.Windows.Forms.DataGrid.get_Item(Int32 rowIndex, Int32 columnIndex)
at App.frmScheduleMonitoring.NextRecord() in C:\frmMainForm.vb:line 3798


I hope my question makes sense to you all, and thank you for your assistance.
 
If you want to access the EXISTING main form then you can't create a NEW main form and expect what you do to it to affect the existing one. That's like having a piece of paper and when you want to write on it you go and get a new piece of paper and write on it. Would you be surprised if the original piece of paper was still blank? I suggest that you follow the first link in my signature and read all four parts. It will explain how to do access one form from another and many other things that you need to know as a WinForms developer.
 
Back
Top