如何插入“空”行放入数据表中?
我正在使用 DevExpress LookUpEdit
控件。我的数据库有两个表来控制控制选项的数量。一种称为 MaintCategory,另一种称为 MaintItem。这在我的程序中引入了一个幻数(CategoryID),但允许大量运行时自定义。
我的问题在于如何允许我的用户取消选择下拉列表,而不必为每个 CategoryID
添加“空”项目。没有办法注入空白行吗?在控制级别或当我构造要返回的 DataTable
时?
这是我用来填充所有控件选择的 DAL 方法。
public static DataTable GetMaintItems(int iCat)
{
using (var context = CmoDataContext.Create())
{
IQueryable<tblAdminMaintItem> tItems = context.GetTable<tblAdminMaintItem>();
return (tItems.Where(item => item.CategoryID == iCat & item.Active == true).OrderBy(item => item.OrderID).Select(
item => new { item.ItemID, item.ItemDescription })).CopyLinqToDataTable();
}
}
I am using a DevExpress LookUpEdit
control. My database has two tables that control the population of control options. One called MaintCategory and one called MaintItem. This introduces a Magic Number into my program(the CategoryID) but allows for lots of runtime customization.
My problem lies in how to allow my users to un-select a dropdown WITHOUT me having to add an "Empty" Item for every CategoryID
. Isn't there a way to inject a blank row? At the control level or when I construct the DataTable
to return?
This is the DAL method that I use to populate all control choices.
public static DataTable GetMaintItems(int iCat)
{
using (var context = CmoDataContext.Create())
{
IQueryable<tblAdminMaintItem> tItems = context.GetTable<tblAdminMaintItem>();
return (tItems.Where(item => item.CategoryID == iCat & item.Active == true).OrderBy(item => item.OrderID).Select(
item => new { item.ItemID, item.ItemDescription })).CopyLinqToDataTable();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实上,我最近在使用 DevExpress 的
LookUpEdit
控件开发的应用程序中遇到了一个非常类似的问题 - 一旦选择了,就无法将控件恢复为没有选择。被做了。我的解决方法是:
LookUpEdit.Properties.AllowNullInput
属性设置为true
。LookUpEdit.Validating
事件。Text
属性是否为空字符串,并手动将EditValue
设置为null
。换句话说,类似这样:
这允许用户清除控件中的文本,并有效地将其值重置为
null
。I actually ran into a very similar issue in an app I was working on recently using DevExpress's
LookUpEdit
control -- the inability to revert the control to having no selection once a selection has been made.My workaround was:
LookUpEdit.Properties.AllowNullInput
property totrue
.LookUpEdit.Validating
event.Text
property and setEditValue
tonull
manually.In other words, something like this:
This allows the user to clear the text in the control, and have this effectively reset its value to
null
.我搜索了devexpress社区内容,发现不能直接在control中添加。
但这可以通过对数据源的操作来完成。
我在这里找到了示例:
http://www.devexpress.com/Support/中心/p/AS13948.aspx
I searched devexpress comunity content and found that it cannot be added directly in control.
But it can be done by manipulations with datasource.
I have found the example here:
http://www.devexpress.com/Support/Center/p/AS13948.aspx
你为什么不尝试这样的事情:
谢谢,
弗洛雷斯
Why don't you try something like this:
Thanks,
Flores