?
Solved

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

Posted on 2011-03-14
5
Medium Priority
?
593 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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 …
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

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