Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 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

21 Experts available now in Live!

Get 1:1 Help Now