Solved

how to access the Datagrid from other form

Posted on 2004-09-24
8
139 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

9 Experts available now in Live!

Get 1:1 Help Now