使用不同形式的值填充DataGridView [英] Populate DataGridView With Values From Different Form

查看:75
本文介绍了使用不同形式的值填充DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想基于另一种形式的数据以一种形式显示数据。



例如:

在一种形式中,fLocations.dgv1,用户选择一行。这会触发dgv1_SelectionChanged事件,它会获取CurrentCell.Value,即'location_id'等于,例如10.



另一种形式,fRooms.dgv1,我想运行一个显示location_id = 10的房间的查询。



这是填充fRooms.dgv1的查询(使用SQL Server表名):

I'd like to display data in one form based on a value in another.

For example:
In one form, fLocations.dgv1, the user selects a row. This fires the dgv1_SelectionChanged event which gets me the CurrentCell.Value which is the 'location_id' equal to, say, 10.

In a different form, fRooms.dgv1, I'd like to run a query that displays rooms for location_id = 10.

Here is the query that populates fRooms.dgv1 (using SQL Server table names):

select *
from room_headers RH
join location_details LD on (RH.room_id = LD.room_id)
join location_headers LH on (LD.location_id = LH.location_id)
where LH.location_id = **the current location_id = 10**



我正在运行Visual Studio C#Express 2008和SQL Server 2008 R2。任何帮助都非常感谢,谢谢。


I am running Visual Studio C# Express 2008 and SQL Server 2008 R2. Any help is greatly appreciated, thanks.

推荐答案

由于这个问题非常受欢迎,我以前的答案往往不太清楚,可能还不够清楚,我决定写一篇提示/技巧文章,详细的代码示例和解释:一次回答的许多问题 - Windows窗体或WPF Windows之间的协作



-SA
As the question turned out to be very popular, and my previous answers often were not well understood, probably were not clear enough, I decided to write a Tips/Trick article complete with detailed code samples and explanations: Many Questions Answered at Once — Collaboration between Windows Forms or WPF Windows.

—SA


这篇关于使用不同形式的值填充DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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