Solved

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

Posted on 2011-03-14
5
590 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
[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
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

752 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