Devexpress从gridview中获取值 [英] Devexpress Get the value from gridview child

查看:581
本文介绍了Devexpress从gridview中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use this code to generate the data and output it in my 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的孩子时,我想实现这样的事情。 thnx提前

Guys. Pls help. i want to achieve something like this when i click on the gridview's children. thnx in advance

推荐答案

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

The main idea in this case is to obtain an instance of the GridView class which was clicked. XtraGrid creates clones of the pattern View which is created at design time and use these clones to disply data. Here is the code which should work:

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

由于您的孩子GridView是自动创建的,所以有两种方法:

Since your child GridView is created automatically, there are two approaches:

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

1) handle the GridControl's Click event handler:

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事件处理程序:

2) handle the GridView1 MasterRowExpanded event handler:

    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());
    }

这篇关于Devexpress从gridview中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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