Solved

how to access the Datagrid from other form

Posted on 2004-09-24
8
143 Views
Last Modified: 2010-04-23
Here is the question

I have a  Form1 where  i Display a set of results and when a user clicks on a row it opens an other form  form2 where it calculates a
value and should post it back to the a cell in the datagird in form1.
Now in a gloabl module i declared both the forms

public PayGrid as new form1()
public DrawGrid as new form2()

and in the second form i coded it as
paygrid.ds.tables(0).Rows(RowNum)(5)=CalculetedValue

where ds and rownum are declared as public in Paygrid form(ie Form1)
but i get an error system.nullreferenceexception
:Object reference not set to an instance of an object.
why?
is there any easy way around?
Please help me ASAP


0
Comment
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 23

Expert Comment

by:Snarf0001
ID: 12145057
When do you show Form1?  Is it the startup form?  If not, are you calling PayGrid.Show or Form1.Show()?
0
 

Author Comment

by:SandhiyaKrishnamoorthy
ID: 12145083
Actually form1 is the startupform and i am not closing the form1 or hiding it.when we click on the row of the dtatgrid in form1 it opens the form2 and the user inputs the value and it calculates and sends it back to the form1's datagrid
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12145122
That is not the way to do it,

if paygrid is your original form
and drawgrid is called from paygrid

then just do

In paygrid

dim drawgrid as new form2
drawgrid.owner = me
drawgrid.show

then in form2 you can just do

ctype(me.owner,form1).ds.tables(0).Rows(RowNum)(5)=CalculatedValue

ofcourse ds should be declared public or friend

so no need for a module
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:Snarf0001
ID: 12145127
Are you actually setting the value of PayGrid then?  That might be the problem, as the line you have in the global module declares paygrid as a completely separate, new instance of the form.

You should have it as
  public PayGrid as form1()

and then on the form_load for form1, put in
  PayGrid = me

This will just declare PayGrid as an object of type Form1, but currently holding nothing.  When form1 is loaded, PayGrid will be set to that instance of the form.

A warning though, this will product very unreliable results if you ever declare another instance of form1.
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 12145138
And the code above mine would be the proper way to do it so you didn't have to worry about unreliable results with multiple instances.
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12145421
Check the accepted answer in this thread:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21126753.html

instead of the dataset you will pass your datagrid.

Public MyDataGrid as DataGrid

in your form.
0
 

Author Comment

by:SandhiyaKrishnamoorthy
ID: 12145668
Thanks Guys,
especially thanks Ronalds ur method works very fine.



0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 125 total points
ID: 12158292
If it works, could you then close the question ;-)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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