从详细信息行获取数据

时间:2013-12-28 20:55:09

标签: winforms devexpress master-detail double-click gridcontrol

如何通过双击从devexress gridcontrol的详细信息行获取数据。 如果我专注于子行gridview的双击事件没有捕获。

我尝试了这种方法,但我的请求是通过双击

来捕获数据
private void gcOperasyonlar_FocusedViewChanged(object sender, DevExpress.XtraGrid.ViewFocusEventArgs e)
        {
            if (e.View != null && e.View.IsDetailView)
            (e.View.ParentView as GridView).FocusedRowHandle = e.View.SourceRowHandle;
            GridView detailView = gcOperasyonlar.FocusedView as GridView;
            MessageBox.Show(detailView.GetFocusedRowCellValue("Kalip").ToString());  
        }

感谢您的帮助

3 个答案:

答案 0 :(得分:0)

我在论坛上发现了这个代码,只要您的网格不可编辑(这样鼠标点击不会激活可编辑字段),它可能会很有用。

private void gridView1_DoubleClick(object sender, EventArgs e) {
    GridView view = (GridView)sender;
    Point pt = view.GridControl.PointToClient(Control.MousePosition);
    DoRowDoubleClick(view, pt);
}      

private static void DoRowDoubleClick(GridView view, Point pt) {
    GridHitInfo info = view.CalcHitInfo(pt);

    if(info.InRow || info.InRowCell) {
        string colCaption = info.Column == null ? "N/A" : info.Column.GetCaption();
        MessageBox.Show(string.Format("DoubleClick on row: {0}, column: {1}.", info.RowHandle, colCaption));
    }
}

http://www.devexpress.com/Support/Center/Question/Details/A2934

答案 1 :(得分:0)

假设您有两个网格视图(我猜您在网格控件中使用了网格视图):gvMaster和gvDetail。

您应该为gvDetail实施事件DoubleClick,以实现所需的功能:

private void gvDetail_DoubleClick(object sender, EventArgs e) {
    var gv = sender as GridView; // sender is not gvDetail! It's an instance of it. You have as many as there are rows in gvMaster
    var row = gv.GetDataRow(e.FocusedRowHandle);  // or use gv.GetRow(e.FocusedRowHandle) if your datasource isn't DataSet/DataTable (anything with DataRows in it)
    MessageBox.Show(row["Kalip"].ToString()); 
}

答案 2 :(得分:0)

还有一种更简单的方法:

ColumnView cv = _gridControlxyz.FocusedView as ColumnView;

selectedRow row = cv.GetRow(cv.FocusedRowHandle)