在表单中使用两个单独的GridControl

时间:2018-04-01 11:39:13

标签: c# devexpress gridcontrol

表单还有两个独立的GridControl,GridControl1在GridControl2中也有联系人姓名电话号码,每个人都有一个任务和持续时间。当我单击我想要执行的GridControl1之一时,有关该人的信息将显示在GridCOntrol2中。

您还可以在下面看到c#DataGridView代码:

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string filter = "";
            if (dataGridView1.CurrentCell != null)
                filter = $"KisiNo = {dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells["KisiNo"].Value}";
            (dataGridView2.DataSource as DataTable).DefaultView.RowFilter = filter;
        }

1 个答案:

答案 0 :(得分:0)

用于显示详细数据的GridControl对象应该绑定到ADO.NET数据关系(如果在DataSet级别有正确组织的数据关系,它将起作用):

gridControl1.DataSource = dataSet1.Contacts;
gridControl2.DataSource = dataSet1.Tasks;
gridControl2.DataMember = "ContactsTasks";

请查看How to Display Master-Detail Tables in Separate Grid Controls了解详情。

P.S。 The GridControl supports embedded master-detail data presentation out-of-the-box - take a look at the documentation to learn more