devexpress 15.1 gridview中加入repositoryitemsearchlookupedit搜索为什么有值的单元

【DevExpress】3、LookUpEdit详解 - fish_1949 - 博客园
哈,今天又用到了LookUpEdit控件,主要是用来实现模糊查询和自由输入功能,然而由于长时间没用了,一阵手忙脚乱的,这里把网上收集的一部分教程汇兑下,方便下次使用●﹏●
一、属性的基本介绍:
绑定数据源:&& &&&& && && && &&&&&&&&&&&&&&& lookUpEdit.Properties.ValueMember = 实际要用的字段;&& //相当于Editvalue&&&&&&&&&&& lookUpEdit.Properties.DisplayMember =要显示的字段;&&& //相当于Text&&&&&&&&&&& lookUpEdit.Properties.DataSource = 数据源;
常用属性:
&&&&&&&&& Popupwidth 下拉框宽度&&&&&&&&& Nulltxt&&& 空时的值& & & & & DropDownRows 下拉框行数& & & & & AllowNullInput =True,可用Ctrl+Delete清空選擇內容
&判断是否选择下拉框:&&& && && && if(this.lookUpEdit.Editvalue==null ||this.lookUpEdit.Editvalue.tostring()=="nulltext")&&& &&& &&&& {&&& && && && && //提示信息,说明未选择下拉框&&& &&& &&&& }&&&&&清空nullText值: &&& &&&&&&& lookUpEdit.Properties.nulltext=
&&设置nullText值:    lookUpEdit.Properties.nulltext=&请您选择&;&&&使用lookUpEdit1的值:&&& && && 变量=this.lookUpEdit.Editvalue.Tostring()  //是LookUpEdit.Properties.ValueMember的值&&& &&& & 变量=this.lookUpEdit.Text.Trim()      //是LookUpEdit.Properties.DisplayMember 的值&&
&&&&&&& 特别值得注意的是,有时候我们要使用lookUpEdit来实现combox的一些效果,在实际的使用过程中在程序加载的时候会默认的选择第一项,它的设置是:
&&&&& &lookUpEdit.Itedex=0;&& //选择第一项
&&&&&& lookUpEdit.Itedex=-1; //无选项,此时显示的是nullText值 其实这个地方只要Editvalue==null,lookUpEdit就显示nullText
&&&&&& lookUpEdit1.Editvalue=value;//自动搜索datasouse,选择与之匹配的值,没有的情况下赋值null ,value的值必须与Valuemember的数据类型一致。
介绍三个重要的属性:1. LookUpEdit.Properties.ImmediatePopup
在输入框按任一可见字符键时立即弹出下拉窗体。2. LookUpEdit.Properties.AutoSearchColumnIndex
设置自动搜索的栏位序号,下拉窗体第一个栏位为0,依此类推,此属性配合SearchMode=OnlyInPopup时有效。3. LookUpEdit.Properties.SearchMode
自动搜索定位模式
关于枚举类型SearchMode的定义:
// Summary:
Enumerates search modes for a lookup
public enum SearchMode
The incremental search is enabled only when the
dropdown window is open.
If the window is closed, the user can modify the text
in the edit box. However
these changes are
When the dropdown is open the incremental search is
performed against the
column whose index is specified by the
DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit.AutoSearchColumnIndex
property. The header of this column contains the
search icon (binoculars).
The user can click a specific column header to
perform the search against
The following screenshot shows a sample lookup editor. The
incremental search
is performed against the second
OnlyInPopup =
Enables the automatic completion feature. In this
mode, when the dropdown
is closed, the text in the edit box is automatically
completed if it matches
DevExpress.XtraEditors.Repository.RepositoryItemLookUpEditBase.DisplayMember
field value of one of dropdown
When the dropdown is open, the automatic completion feature is disabled
editor allows you to perform an incremental search in the same
as when DevExpress.XtraEditors.Controls.SearchMode.OnlyInPopup mode is
AutoComplete =
Enables the incremental filtering feature. When you
type within the edit
box, the editor automatically opens the dropdown
window and displays only
records whose
DevExpress.XtraEditors.Repository.RepositoryItemLookUpEditBase.DisplayMember
field value starts with the characters typed. Other
records are not displayed.
If you enter a value that does not match any record,
the dropdown window
will not contain any
The following image shows a lookup editor when
AutoFilter mode is enabled.
AutoFilter = 2,
OnlyInPopup :
配合ImmediatePopup=True时使用,当用户在输入框按任一可见字符键时立即弹出下拉窗体,并跟据输入的字符从头部开始匹配AutoSearchColumnIndex属性指定栏位字段的值,第一个栏位为0.
特点:在下拉窗体能显示匹配结果(蓝底白字),但在输入框内不显示。效果图如下:
AutoComplete:
配合ImmediatePopup=True时使用,当用户在输入框按任一可见字符键时立即弹出下拉窗体,并在输入框自动完成您想要输入的数据,同时下拉窗体自动匹配最佳记录。AutoComplete模式仅匹配DisplayMember对应字段的值。特点:能在输入框显示匹配的数据,并且下拉窗体显示匹配的记录。效果图如下:
AutoFilter:
配合ImmediatePopup=True时使用,当用户在输入框按任一可见字符键时立即弹出下拉窗体,并在输入框自动完成您想要输入的数据,同时下拉窗体自动过滤掉不匹配的记录。特点:能在输入框显示匹配的数据,并过滤过不想要的记录。
二、具体的使用:
看过了上面属性的介绍,一般的使用已经够了,但有的情况下,允许用户自由输入,即输入的值不一定是在绑定的数据源中,光用上面的属性就不行了,因为就算你输入的内容不在数据库中,控件也会帮你选中数据源中第一条数据,清空你输入的数据,恼火。。可以用下面的方法解决:
The LookUp editor allows a user to enter values which cannot be found in the lookup list. A programmer should handle this situation, otherwise a new value is lost. The LookUp editor provides a&ProcessNewValue&event for this.
First of all, you should set the&SearchMode&property to&OnlyInPopup&and&TextEditStyle&to&Standard&to enable free text entry.
There are two common approaches for handling the ProcessNewValue event:1. Immediately insert the new record in the lookup table and generate a new ID for it.2. Display a dialog, where a user can set values for a new data row.
List&std_MetaInfo& source = DataHelper.MetaI//数据源
EditorHelper.BindLookUpEdit(lueStdNO, source, "StdNO", "StdNO");//
lueStdNO.ProcessNewValue += lue_ProcessNewV
//实现自由输入功能
private void lue_ProcessNewValue(object sender, ProcessNewValueEventArgs e)
RepositoryItemLookUpEdit edit = ((LookUpEdit)sender).P
if (e.DisplayValue == null || edit.NullText.Equals(e.DisplayValue) || string.Empty.Equals(e.DisplayValue))
return;//为空或者选择项不变,不执行后续操作
std_MetaInfo meta = new std_MetaInfo();
meta.StdNO = e.DisplayValue.ToString();
source.Add(meta);//在数据源中添加一条记录,如果数据源是DataTable,添加DataRow,其他形式数据源解决方法类似
e.Handled = true;
public class EditorHelper
public static void BindLookUpEdit(LookUpEdit lue, object source, string value, string displayName)
lue.Properties.DataSource =
lue.Properties.DisplayMember = displayN
lue.Properties.ValueMember =
lue.Properties.NullText = "";
lue.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.S//要使用户可以输入,这里须设为Standard
lue.Properties.SearchMode = SearchMode.AutoF//自动过滤掉不需要显示的数据,可以根据需要变化
private void LookUpEdit1_ProcessNewValue(object sender, DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs e)
RepositoryItemLookUpEdit Edit = ((LookUpEdit)sender).P
if (e.DisplayValue == null || Edit.NullText.Equals(e.DisplayValue) || string.Empty.Equals(e.DisplayValue))
using (Form2 f = new Form2())
f.ItemID = "(Auto Number)";
f.ItemName = e.DisplayValue.ToString();//ItemName是Form2中的一个属性,return Form2中一个文本框的值
if (f.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
e.DisplayValue = f.ItemN
Row = LookupTable.NewRow();
Row["Name"] = f.ItemN
LookupTable.Rows.Add(Row);
e.Handled = true;
上面的够一般使用了,以后有什么更高级的用法再添加了,暂时就这样子了。。。
参考网址:/Support/Center/p/A238.aspx
/liran/archive//1400402.html
.cn/s/blog_6d1c583c01011qiv.html
评论 - 102较早之前,曾经介绍了一篇文章《使用DataGridView数据窗口控件,构建用户快速输入体验》,介绍了在传统DataGridView中嵌入一个数据窗口进行选择列表,从而实现数据快速录入的操作例子,在DevExpress的控件使用中,我们应该如何实现这种效果呢,本文首先通过简单的例子介绍一下,具体的实现过程。然后进阶具体的应用,指导我们实际的开发工作,以及在使用过程中需要注意的一些特殊问题,提供相应的解决方法。1、 GridControl集成SearchLookUpEdit的效果展现首先我们来介绍一下整个效果图,以便有感性的印象。1)启动后默认效果2)弹出窗体效果3)选中数据后效果图其实上面是一个测试的例子,具体的应用会比较复杂一点,不过操作过程差不多,我们都是在一个Cell里面嵌入一个可以选择(包括查询)的数据列表,从中选择我们需要的内容,然后可以在另外一个Cell中输入一些其他的信息,保存的时候,一并保存即可。2、GridControl集成SearchLookUpEdit的实现过程在开始介绍之前,我们要清楚,这个GridControl必须先绑定数据源(数据源可以为空),如果不绑定数据源,那么虽然可以弹出列表供选择,但是鼠标移开值就会丢失的问题,一开始不明白其中道理,搞了很久。首先要为GridControl添加两个字段,设置好他们的显示Caption和FieldName即可,然后在我们需要弹出窗口的单元格对象中,选择它的ColumnEdit控件为SearchLookup控件即可,如下所示。这个时候,它会生成一个repositoryItemSearchLookUpEdit1的控件,这个控件就是该单元格的内嵌编辑控件了,可以从中选择列表的值,我们设置这个列表的DisplayMember为Name(显示的字段内容),ValueMember为ID(保存的值字段),如下所示。除了你要设置主窗体里面的GridControl运行添加列外,你还需要设置编辑控件里面的View中OpitonsView里面的NewItemRowPosition为Botton(默认为None),这一步很重要,否则无法出现一个新建的行给你录入数据的。例子代码比较简单,主要是为了演示这种方式的使用,代码如下所示
DataTable dt = new DataTable();
private void Form1_Load(object sender, EventArgs e)
dt.Columns.Add("ID");
dt.Columns.Add("Name");
for (int i = 0; i & 100; i++)
DataRow row = dt.NewRow();
row["ID"] = i.ToString();
row["Name"] = (new Random()).NextDouble().ToString();
dt.Rows.Add(row);
System.Threading.Thread.Sleep(1);
this.repositoryItemSearchLookUpEdit1.DataSource =
this.gridControl1.DataSource = dt.Clone();
private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
if (e.Column.FieldName == "ID")
string id = e.Value.ToString();
DataRow[] dr = dt.Select(string.Format("ID = '{0}'", id));
if(dr != null && dr.Length & 0)
DataRow row = dr[0];
string name = row["Name"].ToString();
gridView1.SetRowCellValue(e.RowHandle, "Name", name);
}3、&GridControl集成SearchLookUpEdit的实际案例操作一个实际的案例就是门诊的时候,医生用药的情况,除了选择其他内容外,主要的就是快速录入药品信息。我们平常去大一点 的医院看病,好像看到的多数操作都是这样。还有一种方式就是销售人员提供的报价单,从产品里面选择信息,然后修改下价格,这些场景都是很适合这样的操作的。下面是一个门诊的例子。在实际应用中,我们在编辑一些历史数据的时候,不希望原来的记录被修改,但是可以增加新的记录,但是前面所有介绍的内容,没有能够解决这个问题,那么我们应该如何操作才能实现这个效果呢?其实GridView对象里面有一个ShowingEditor的事件,用来判断是否显示单元格的编辑器的,这样我们对数据库已有记录进行控制,不让它在列表中显示编辑控件出来即可,具体代码如下所示。
this.gridView1.ShowingEditor += new CancelEventHandler(gridView1_ShowingEditor);//实际使用的代码
void gridView1_ShowingEditor(object sender, CancelEventArgs e)
object ID = this.gridView1.GetRowCellValue(this.gridView1.FocusedRowHandle, "ID");
if (ID != null && !string.IsNullOrEmpty(ID.ToString()))
e.Cancel =
}在保持数据的时候,我们对历史数据就不用修改保持,只需要针对新增的内容即可,如何做到的呢?其实就是判定他的绑定值是否存在即可,如果有绑定值,那么就是历史的数据,没有就是新的,进行特殊操作即可,如下代码所示。
if (this.gridView1.RowCount & 0)
#region 提交用药记录明细
for (int i = 0; i & this.gridView1.RowC i++)
//根据ID来判断是否新增的用药记录
object ID = this.gridView1.GetRowCellValue(i, "ID");
if (ID == null || string.IsNullOrEmpty(ID.ToString()))
//.........................
#endregion
、 、 、 、 、RepositoryItemSearchLookUpEdit 怎么使用,怎么得到选择值_百度知道
RepositoryItemSearchLookUpEdit 怎么使用,怎么得到选择值
ColumnEdit =ri&quot.VrepositoryItemSearchLookUpEdit1View&&#47.ColumnEdit =选择好需要的数据后;//;
GridColumn gc = new GridColumn();/所属部门&gridColumn1&//&#47.ValueMember = &/&#47.Columns[&//.Visible =/;;
gc.AutoHeight =&#47.View = rv.EnableAppearanceFocusedCell =&#47.FieldName = &quot.Caption = &;&#47.XtraGrid.NullText = &).Columns,不知道怎么回事;所属部门&//id&//
/];/部门&
rv = new GridView();这个话报错.DataSource =&#47.Columns?/
ri.Name = &&#47.Name = &/
rv.OptionsV&#47.Tables[&quot.GetFocusedRowCellValue(&quot,请高手指教这是怎么回事.V////
rv.FocusRectStyle = DevExpress.Visible =/&#47.ShowGroupPanel =
gridView1;ri,始终得不到需要的值;
ri.Add(gc);].V.Columns[&dep&/&#47.RowF////id&quot.DisplayMember = &/
GridV&&#47.Visible =/////id&id&.OptionsSelection.G&#47RepositoryItemSearchLookUpEdit ri = new RepositoryItemSearchLookUpEdit().View.V&#47.ToString()
/&#47.VisibleIndex = 0.Name = &.DrawFocusRectS]
我有更好的答案
可以手动创建列,如;):ri.AddField(&quot,从BarEditItem.editvalue中获得.View.在这中情况下GridView无法自动创建列;id&quot.Visible=false,必须通过上级组件过得;2.这是一个组件的子组件.Columns1,比如BarEditItem定义了edit的组件为RepositoryItemSearchLookUpEdit
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁Devexpress GridControl中RepositoryItemLookUpEdit级联显示控制_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
Devexpress GridControl中RepositoryItemLookUpEdit级联显示控制
上传于||文档简介
&&D​e​v​e​x​p​r​e​s​s​ ​G​r​i​d​C​o​n​t​r​o​l​中​R​e​p​o​s​i​t​o​r​y​I​t​e​m​L​o​o​k​U​p​E​d​i​t​级​联​显​示​控​制
阅读已结束,如果下载本文需要使用0下载券
想免费下载更多文档?
你可能喜欢&DevExpress控件使用交流,DevExpress中国社区
当前位置:
& DevExpress XtraEditors SearchLookUpEdit - 运行时创建列
DevExpress XtraEditors SearchLookUpEdit - 运行时创建列
作者:huhm&&&来源:本站原创&&&浏览:Loading...次&&&发布时间:&&&评论:
问题描述:我有一个关于&SearchLookUpEdit&控件的问题:如何在浏览运行时创建列?可能吗?最好是有个例子或代码片段,介绍如何在运行popup-control/grid创建列。问题解答:使用一个GridView对象以编程方式创建列。您可以通过访问它SearchLookUpEdit.Properties.View属性&。请尝试以下代码行:[C#]GridColumn column = searchLookUpEdit1.Properties.View.Columns.AddField(&CustomerID&);
&&&&&&&column.Visible =
&&&&&&&column = searchLookUpEdit1.Properties.View.Columns.AddField(&Date&);
&&&&&&&column.Visible = 版本信息:v2011 vol 2.11系统信息:Windows 7&相关平台:.NET&WinForms相关产品:XtraEditors Library
本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 []
本文地址:
相关产品:
请谈谈你的看法 请使用IE或者Firefox浏览器,暂不支持Chrome!
为DevExpress界面控件的中国地区唯一正式授权经销商,正版控件销售公司,授权代理商,经销商及合作伙伴。
电话:400-700-1020
&&&&&&&&023-
400-700-1020

我要回帖

更多关于 lookupedit 的文章

 

随机推荐