GridView——MasterDetail获取子表数据方法

微博:https://weibo.com/6274976536/profile?rightmod=1&wvr=6&mod=personinfo&is_all=1

1.     记录鼠标点击子表的位置。

  Point p = new Point();


        private void gv_term5_MouseDown(object sender, MouseEventArgs e)
        {
            p.X = e.Location.X;
            p.Y = e.Location.Y;
        }

2.   获取子表  鼠标点击的数据

private void gv_term5_RowClick(object sender, RowClickEventArgs e)
        {
            try
            {
                rowhandle = e.RowHandle;
                //rowhandle : 记录当前选中子表序号 在其他地方 需要获取 当前选中数据时使用
                if (e.Clicks>=2)
                {
                    DataTable
dt = ((System.Data.DataView)(this.gc_F4.GetViewAt(p).DataSource)).ToTable();

// gc_f4 :当前gridcontrol

// p :鼠标位置

// dt: 当前子表数据
                    if (dt != null && dt.Rows.Count >= e.RowHandle)
                    {
                        DataRow obj = dt.Rows[e.RowHandle]; //获取选中的子表数据
                        if (obj != null)
                        {
                           
// ……
                        }
                    }
                    
                }
            }
            catch (Exception ex)
            {
                //……
            }
        }


3. 其他方法中获取选中的子表数据

  private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if (this.gv_F4.FocusedRowHandle >= 0)
                {
                    if (
rowhandle > 0)//rowhandle: 由上个方法中记录
                    {
                        DataTable dt = ((System.Data.DataView)(this.
gc_F4.GetViewAt(p).DataSource)).ToTable();
                        if (dt != null && dt.Rows.Count >=
rowhandle)
                        {
                            DataRow obj = dt.Rows[
rowhandle];
                            if (obj != null)
                            {
                                //……
                            }
                        }
                    }
                    else
                    {
                        //……
                    }
                }


            }
            catch (Exception ex)
            {
                //……
            }
        }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值