?
Solved

how to access the Datagrid from other form

Posted on 2004-09-24
8
Medium Priority
?
145 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 500 total points
ID: 12158292
If it works, could you then close the question ;-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

800 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