如果我有两个网格视图。如何单击第二个网格视图上的单元格并显示第一个和第二个网格视图的数据 [英] If I've two grid view. How can i click on a cell on the second grid view and display both data of first and second grid view

查看:57
本文介绍了如果我有两个网格视图。如何单击第二个网格视图上的单元格并显示第一个和第二个网格视图的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我搜索了两天如何点击第二个网格视图并在文本框中显示第一个和第二个网格视图的数据 和combobox,但搜索后,我得到一个代码,通过点击第二个网格视图进行选择

I searched for two days on how to click on second grid view and display the data of both first and second grid view on the textbox  and combobox but after searching i get a code to make a selection on both grid view by clicking on second one

这个代码进行选择

 Private Sub DataGridView3_SelectionChanged(sender As Object, e As EventArgs) Handles DataGridView3.SelectionChanged
        Dim dgv As DataGridView = DirectCast(sender, DataGridView)
        Dim rowindex As Int32 = dgv.CurrentCell.RowIndex
        If rowindex >= 0 AndAlso rowindex < Me.DataGridView4.Rows.Count Then
            Me.DataGridView4.CurrentCell = Me.DataGridView4.Rows(rowindex).Cells(0)
        End If
    End Sub

是否有代码通过点击其中任何一个来显示两个网格的数据?

Is there a code to display the data of both grid by clicking on any one of them ?

提前致谢.....

来自Amr_Aly

推荐答案

如果所有DataGridView控件中的数据都有然后设置一个DataSet,其中每个DataTable成为DataGridView的DataSource,在DataSet中设置关系。这称为主 - 细节关系。

If data in all the DataGridView controls have a relationship then set up a DataSet where each DataTable becomes the DataSource of a DataGridView, setup the relationship in the DataSet. This is called a master-detail relationship.

以下
代码示例
执行三个关系并在三个ListBox控件中显示它们,使用DataGridView控件可以完全相同。使用ListBox的唯一原因是专注于任务。

这是相同的逻辑
三个DataGridView控件(我开始使用ListBox的第一个代码示例,因为它更容易遵循)。

The following code sample does three relations and display them in three ListBox controls, the exact same thing can be done with DataGridView controls. The only reason for using a ListBox is for focusing on the task. Here is the same logic doing three DataGridView controls (I started off with the first code sample with ListBox as it's easier to follow).

无论是移动DataGridView或ListBox中的选择,都会更改其他控件。要将数据放入TextBox,只需数据绑定,例如someTextBox.DataBindings.Add ..... ComboBox可以通过关系或通过(和所有示例
这里使用BindinSource)处理BindingSource的PositionChange事件来处理。

Either way moving the selection in either the DataGridView or ListBox changes the other controls. To place data into a TextBox simply data bind e.g. someTextBox.DataBindings.Add..... A ComboBox can be handled via the relationship or via (and all the examples here use a BindinSource) PositionChange event of the BindingSource.

当需要从BindingSource的当前项获取数据时,我们可以使用

When needing to get data from the current item for a BindingSource we can use

Dim Row As DataRow = CType(someBindingSource.Current,DataRowView).Row

Dim Row As DataRow = CType(someBindingSource.Current,DataRowView).Row

以名字说出

Dim firstName As String = Row.Field(Of String)(" FirstName")

Dim firstName As String = Row.Field(Of String)("FirstName")


  • 如果您没有DataGridView控件的DataSource,那么这样做只会这样。
  • 我使用了数据对于这两个示例的数据库,不必是,DataSet / DataTable可以保存不是来自数据库的其他类型的数据。


这篇关于如果我有两个网格视图。如何单击第二个网格视图上的单元格并显示第一个和第二个网格视图的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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