如何在C#中从另一个类访问Datagridview? [英] How Can I Access A Datagridview From Another Class In C#?

查看:601
本文介绍了如何在C#中从另一个类访问Datagridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个datagridview,我希望从同一个项目中的另一个类访问它。我怎样才能实现这个目标?

P.S.使修改器公开为datagridview没有帮助。



谢谢

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

推荐答案

如果它是一个asp .net应用程序,我们有代码,所以你不能使用它,但如果你做一个用户控件并把你的gridview放在那里,有一种方法可以使用它。您可以在项目中的任何位置注册和使用它。
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.


您可以做的是

只需在类中创建一个方法,将gridview对象传递给参数并尝试使用该类中方法内的对象。这将是有意义的,因为您可以操作或对网格进行操作,其中数据显示在屏幕上。



如果您尝试访问gridview一个带有公共变量的类,您将获得一个Gridview对象的新实例。这是没用的。



我希望你理解。
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.


这篇关于如何在C#中从另一个类访问Datagridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆