微博: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)
{
//……
}
}