简体   繁体   English

更改DataGridView连接并基于选择C#在其他表单上查询

[英]Change DataGridView connection and query on another form based on selection c#

I've been trying to find an answer for this and I'm completely lost. 我一直在寻找答案,但我完全迷失了。 I have an application that starts with a logon screen, after the client is logged on, it opens an MDI Form in which I have some items on a menu strip. 我有一个从登录屏幕开始的应用程序,在客户端登录后,它会打开一个MDI表单,其中的菜单栏上有一些项目。 One of them are assets (which is what the app will be used for), and the assets menu has a drop down with different assets to select, PC's, software etc. 其中之一是资产(这是应用程序将使用的资产),并且资产菜单中有一个下拉菜单,其中包含可供选择的不同资产,PC,软件等。

When you click on PC's, another window opens within the MDI Form that has a DataGridView on it. 当您单击PC时,会在MDI表单中打开另一个窗口,上面有一个DataGridView。 And it works great but, I don't want to create a window for each and every connection or table in my databases, I feel this is bad practice. 它很好用,但是,我不想为数据库中的每个连接或表创建一个窗口,我觉得这是一种不好的做法。

So what I want is, to be able to change the DGV based on the asset selection, but for the life of me I can't figure out how to do this. 因此,我想要的是能够根据资产选择来更改DGV,但是对于我来说,我一生不知道该怎么做。 I've been trying to pass parameters from one form to the other but the I just get different errors etc. 我一直试图将参数从一种形式传递到另一种形式,但是我只是得到了不同的错误等。

Can you guys please point me in the right direction? 你们能给我指出正确的方向吗? I am new to visual studio etc and want to learn these things, so I'm not asking for freebies so to speak, just what the logic should look like more or less. 我是Visual Studio等的新手,并且想学习这些东西,所以我并不是在要求免费的东西,可以这么说,只是逻辑应该多少看起来像什么。

Thanx!! 谢谢!!

在此处输入图片说明DGV

I don't have code for what I'm trying to do because I have no idea what the logic should look like. 我没有要执行的代码,因为我不知道逻辑应该是什么样。

I'm still trying wrap my head around how two forms communicate in a way I need. 我仍在尝试着围绕两种表单如何以所需的方式进行交流。 I'm used having variables in a loop and when they change values the result changes. 我习惯于在循环中使用变量,当它们更改值时,结果也会更改。 But in visual studio everything needs to be called which makes it a bit difficult for a rookie like me. 但是在Visual Studio中,所有东西都需要调用,这对于像我这样的菜鸟来说有点困难。

I did try sending sql commands via variables, but read that, that is a very bad idea. 我确实尝试通过变量发送sql命令,但读过,那是一个非常糟糕的主意。

I just want the DGV to change the data its showing based on a button selection. 我只希望DGV根据按钮选择更改其显示的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM