2

我使用此代码生成数据并将其输出到我的 gridview

string sql = "Sql Query";
string sqlCredit= "Sql Query";
string sqlCreditPayment = "Sql Query";

  SqlDataAdapter da = new SqlDataAdapter();

    DataSet ds = new DataSet();
    ds.EnforceConstraints = false;
    ds.DataSetName = "Receivables";

    ds.Tables.Add((con.ShowResult(sql, ref da)).Tables[0].Copy());
    ds.Tables[0].TableName = "dtReceivables";

    ds.Tables.Add((con.ShowResult(sqlCredit, ref da)).Tables[0].Copy());
    ds.Tables[1].TableName = "dtCredit";
    ds.Tables[1].Columns[1].ColumnMapping = MappingType.Hidden;
    ds.Tables[1].Columns[7].ColumnMapping = MappingType.Hidden;

    ds.Tables.Add((con.ShowResult(sqlCreditPayment, ref da)).Tables[0].Copy());
    ds.Tables[2].TableName = "dtCreditPayment";
    ds.Tables[2].Columns[0].ColumnMapping = MappingType.Hidden;

    DataRelation dr0 = new DataRelation("CreditList", ds.Tables[0].Columns["Id"], ds.Tables[1].Columns["DocSupplierId"]);

    ds.Relations.Add(dr0);


    DataRelation dr1 = new DataRelation("CreditPaymentList", ds.Tables[1].Columns["Id"], ds.Tables[2].Columns["SourceId"]);
    ds.Relations.Add(dr1);



    slipDashBoard.DataSource = ds.Tables["dtReceivables"];

    slipDashBoard.ForceInitialize();
    gridView1.BestFitColumns();

伙计们。请帮忙。当我点击gridview的孩子时,我想实现这样的目标。提前谢谢

在此处输入图像描述

4

2 回答 2

7

在这种情况下,主要思想是获取被单击的 GridView 类的实例。XtraGrid 创建在设计时创建的模式视图的克隆,并使用这些克隆来显示数据。这是应该工作的代码:

GridView gridView = sender as GridView;
var value = gridView.GetRowCellValue(gridView.FocusedRowHandle, gridView.Columns["Num"));
MessageBox.Show(value.ToString());

由于您的子 GridView 是自动创建的,因此有两种方法:

1) 处理 GridControl 的 Click 事件处理程序:

private void gridControl1_Click(object sender, EventArgs e) {
    GridControl grid = sender as GridControl;
    Point p = new Point(((MouseEventArgs)e).X, ((MouseEventArgs)e).Y);
    GridView gridView = grid.GetViewAt(p) as GridView;
    if(gridView != null)
        MessageBox.Show(gridView.GetFocusedRowCellDisplayText("Num"));
}

2) 处理 GridView1 MasterRowExpanded 事件处理程序:

    private void gridView1_MasterRowExpanded(object sender, CustomMasterRowEventArgs e) {
        GridView master = sender as GridView;
        GridView detail = master.GetDetailView(e.RowHandle, e.RelationIndex) as GridView;
        detail.Click += new EventHandler(detail_Click);
    }

    void detail_Click(object sender, EventArgs e) {
            GridView gridView = sender as GridView;
var value = gridView.GetRowCellValue(gridView.FocusedRowHandle, gridView.Columns["Num"));
MessageBox.Show(value.ToString());
    }
于 2013-01-03T08:42:08.243 回答
0

如果您在运行时创建网格,您将拥有一个类似 gridview2 的实例。现在您可以添加点击事件gridview2.Click += new EventHandler(gridview2_Click);

然后你会得到某事。像这样:

    void view_Click(object sender, EventArgs e)
    {
       //take the code from platons post...
    }
于 2013-01-03T09:28:29.370 回答