实测可行
#region 使用PopupContainerEdit和PopupContainer实现数据展示!!!
/// <summary>
/// 设置一个标识,是否在GridView中可以接受回车键
/// </summary>
bool canAcceptReturn = false;
private void popupContainerEdit1_KeyPress(object sender, KeyPressEventArgs e)
{
//回车的时候绑定数据源,并设置
if (e.KeyChar == '\r')
{
this.popupContainerEdit1.Properties.PopupControl = this.popupContainerControl1;
BindPopupContainerEditData();
this.popupContainerEdit1.ShowPopup();
this.gridView3.Focus();
canAcceptReturn = false;
}
else
{
this.ActiveControl = this.popupContainerEdit1;
this.popupContainerEdit1.Focus();
}
}
/// <summary>
/// 绑定GridView的数据源
/// </summary>
private void BindPopupContainerEditData()
{
var value = this.popupContainerEdit1.Text;
string condition = string.Format(@" SELECT FBILLNO ,
FSHORTNAME ,
FNUMBER ,
FNAME ,
xs_qty ,
F_DJD_CUSTPO ,
FORDERNO ,
FROWSEQ FROM CXHDJ.dbo.T_K3_XSFH_FHD
WHERE FSALEORGID={0} AND FBILLNO LIKE '%{1}%'",
new object[] {this.user.GroupCode , value });
this.gridControl3.DataSource = null;
DataSet ds = CommonServerAccess.CommonSelectSQLStr(condition, "connStr2");
this.gridControl3.DataSource = ds.Tables[0];
}
private void GetSelectValue(bool closePopup = true)
{
var FBILLNO = string.Concat(this.gridView3.GetFocusedRowCellValue("FBILLNO"));
var F_DJD_CUSTPO = string.Concat(this.gridView3.GetFocusedRowCellValue("F_DJD_CUSTPO"));
this.popupContainerEdit1.Text = FBILLNO;
this.txtCustPOnew.Text = F_DJD_CUSTPO;
if (closePopup)
{
this.popupContainerEdit1.ClosePopup();
}
this.popupContainerEdit1.Properties.PopupControl = null;
}
private void popupContainerControl1_Leave(object sender, EventArgs e)
{
//容器退出的时候,重新定位焦点到编辑框
this.popupContainerEdit1.Focus();
}
private void gridView3_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
{
//GetSelectValue();
}
private void gridControl3_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (canAcceptReturn)
{
GetSelectValue();
}
canAcceptReturn = true;
}
}
private void BindGridLookupEdit(GridLookUpEdit gridLookUpEdit, DataTable dtt, string ValueMember, string DisplayMember)
{
//绑定
gridLookUpEdit.Properties.DataSource = dtt;
gridLookUpEdit.Properties.ValueMember = ValueMember; //"Stu_ID";
gridLookUpEdit.Properties.DisplayMember = ValueMember; //"Stu_Name";
gridLookUpEdit.Properties.View.OptionsBehavior.AutoPopulateColumns = true;
//默认值
gridLookUpEdit.Properties.NullText = "";
//文本居中对齐
gridLookUpEdit.Properties.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Default;
gridLookUpEdit.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
gridLookUpEdit.Properties.View.BestFitColumns();
//显示不显示grid上第一个空行,也是用于检索的应用
gridLookUpEdit.Properties.View.OptionsView.ShowAutoFilterRow = true;
//下面两行是为了更好的用户体验
gridLookUpEdit.Properties.AutoComplete = false;
gridLookUpEdit.Properties.ImmediatePopup = true;
gridLookUpEdit.Properties.PopupFilterMode = DevExpress.XtraEditors.PopupFilterMode.Contains;
//能否够输入内容进行检索(还是仅仅能使用选择输入)
gridLookUpEdit.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
//是否显示底部
gridLookUpEdit.Properties.ShowFooter = false;
}
private void uiTabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.uiTabControl1.SelectedIndex.Equals(2))
{
if (this.dtfhd==null)
{
string condition = string.Format(@"SELECT m1.xsfh_id ,
m1.fh_billno ,
m1.cust_po ,
m1.cust_short_name ,
m1.mat_no FROM cxhdj.dbo.T_XSFH_ZB m1 WHERE m1.fac_id ={0}",
new object[] { this.user.GroupCode });
this.gridControl3.DataSource = null;
DataSet ds = CommonServerAccess.CommonSelectSQLStr(condition, "connStr2");
this.dtfhd = ds.Tables[0];
BindGridLookupEdit(this.gridLookUpEdit1, this.dtfhd, "fh_billno", "fh_billno");
}
}
}
private void gridLookUpEdit1_EditValueChanged(object sender, EventArgs e)
{
//获取其他列的值
GridLookUpEdit gridLookUpEdit = sender as GridLookUpEdit;
if (gridLookUpEdit.EditValue != null && gridLookUpEdit.EditValue.ToString().Length > 0)
{
if (gridLookUpEdit.Properties.View.RowCount > 0 && gridLookUpEdit.Properties.View.SelectedRowsCount > 0)
{
string cust_po = gridLookUpEdit.Properties.View.GetFocusedRowCellValue("cust_po").ToString();
string xsfh_id = gridLookUpEdit.Properties.View.GetFocusedRowCellValue("xsfh_id").ToString();
this.txtcustpo.Text = cust_po;
this.txtxsfh_id.Text = xsfh_id;
}
}
}
private void gridView3_DoubleClick(object sender, EventArgs e)
{
GetSelectValue();
}
#endregion