Solved

How do I load a datagridview on a from from another form?

Posted on 2011-03-14
5
588 Views
Last Modified: 2012-05-11
I have a form that contains a datagridview.  The user can manually load the datagridview or they can click a button that will launch another form that will browse for a file, read the data from the file and post it to the datagridview on the original form.  Within the button_click event on Form2 I have tried to add rows to the datagridview on Form1 to no avail.  I have stepped through the code on Form2 and it is executing the DataGridView1.Rows.Add statement but nothing appears in the datagridview when Form2 closes.  Any thoughts?
0
Comment
Question by:StoneCutter3
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 35130606
can we have a look atyour code? There may be something that may seem correct to you BUT turn out to be wrong. Otherwise, the code logic you describe above SHOULD do what you want.
0
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35130632
Hi,

How are you accessing the Datagridview in form1?

I assume that in your form1 you are calling the form2, so you can pass it the instance of form1 so you can access the datagridview, something like this

Dim f2 as New Form2
f2.Owner = Me 'Here you are passing the instance of Form1 to Form2
f2.ShowDialog

Inside the Form2 button_event you use the Owner property to get the instance of the Form1

dim f1 as form = Ctype(Me.Owner, form1)

And to access the Datagridview

f1.Datagridview1.Rows.Add(yourrow)

Hope that helps


0
 

Author Comment

by:StoneCutter3
ID: 35130987
I'm getting a "dgvGreigeGoodsRolls is not a member of System.Windows.Forms.Form" build error on the ".Rows.Add" statement.

'Form 1 Button_Event
        Dim frmOrderEntryGreigeGoodsImport As New Order_Entry_GreigeGoods_Import
        frmOrderEntryGreigeGoodsImport.Owner = Me
        frmOrderEntryGreigeGoodsImport.ShowDialog()

'Form 2 Button_Event
        Dim strReadBuffer As String
        Dim intGreigeGoodsRollNumber As Integer
        Dim intTotalYards As Integer
        Dim frmOrderEntryGreigeGoods As Form = CType(Me.Owner, Order_Entry_GreigeGoods)
        FileOpen(1, "..\Imports\GreigeRolls.txt", OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
        While Not EOF(1)
            strReadBuffer = LineInput(1)
            frmOrderEntryGreigeGoods.dgvGreigeGoodsRolls.Rows.Add(intGreigeGoodsRollNumber, Mid(strReadBuffer, 12, 9), dReader1("ConstructionID"), "", Mid(strReadBuffer, 22, 4), Mid(strReadBuffer, 29, 4), 0, CInt(Mid(strReadBuffer, 36, 4)))

Open in new window

0
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 500 total points
ID: 35131026
Ok, change this line

Dim frmOrderEntryGreigeGoods As Form = CType(Me.Owner, Order_Entry_GreigeGoods)

For this one

Dim frmOrderEntryGreigeGoods As Order_Entry_GreigeGoods = CType(Me.Owner, Order_Entry_GreigeGoods)

Also the dgvGreigeGoodsRolls in Order_Entry_GreigeGoods should have set the MODIFIERS property to PUBLIC
0
 

Author Closing Comment

by:StoneCutter3
ID: 35138233
Thanks!  That worked great!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB 2005 Tooltips on Form Load Event 15 34
How to open form using item in Listbox. 8 23
Get distinct values from excel or comm seperated file 4 30
VB.Net. Reading xml value 6 29
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

840 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