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
Solved

how to access the Datagrid from other form

Posted on 2004-09-24
8
142 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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 22

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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
LVL 22

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 22

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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