Solved

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

Posted on 2011-03-14
5
586 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

914 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

16 Experts available now in Live!

Get 1:1 Help Now