Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

i have a datagridview and i want it to be accessed from another class within the same project. How can i achieve this?
P.S. Making the modifier "public" for datagridview isnt helping.

Thanks
Posted
Comments
Animesh Datta 30-May-14 5:10am    
what is the exact problem ?
sovit agarwal 30-May-14 6:44am    
Initially during form setup, the datagridview,visible is set to false.
Depending on whether files are fetched or not, the datagridview.Visible is set to true and the values arepopulated in the datagridview. Buth the problem is that the datagridview needs to be updated from another class and not from the form class. How is it possible to achieve the same
Animesh Datta 30-May-14 7:16am    
Try to follow what KARTHIK said. You must create one method in the class which will accept the object of DataGridView . now make the changes in that object where the data is showing .
sovit agarwal 30-May-14 8:06am    
can u be a bit more specific and can u plz give me a code snippet for the same!!!
That would do me a world of goods.

If It is an asp.net application, we have code behind so, you can not use it, but there is a way to use it if you make a user control and put your gridview in that. you can register and use it any where you want in your project.
 
Share this answer
 
Comments
sovit agarwal 30-May-14 5:08am    
its not asp.net but its windows form...
what you can do is
just create a method in the class passing the gridview object as the parameter and try to use the object inside the method in that class. this will make some sense as you can manipulate or do something with the grid, in which the data is present on the screen.

if you try to access the gridview from a class with public variable, you will just get a new instance of the Gridview object. which is of no use.

i hope you understood.
 
Share this answer
 
Comments
sovit agarwal 30-May-14 5:20am    
Thanks Karthik!!!
But i need to update the visibilty of the datagridview to "true" and then populate the rows at runtime. So i wanted to ask what will the method exactly contain...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900