数据绑定文本框默认值 [英] Databound TextBox Default Value

查看:82
本文介绍了数据绑定文本框默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据绑定明细表.我想双重用于a)列出所有项目,b)过滤到一组项目.

因此,表单包含以下各项:自动生成ID(aID),另一个ID(bID)和其他一些数据字段.

我添加了一个构造函数重载以传递bID值,并向该表的DataSet上的TableAdapter添加了一个查询,该查询通过该ID返回值.

一切正常,例如,如果我将数据直接输入到表中.

但是,如果用户想输入一条新记录(使用BindingNavigator的添加按钮),我想用传递给表单的值(如果有的话)预先填充bID字段,然后将该字段设置为readonly这样他们就无法承担一切.

但是我就是无法正常工作.我已经尝试了BindingSource的AddingNew,CurrentChanged和CurrentItemChanged事件...但是没有任何作用.即,我有:

I''ve got a data bound detail form. That I want to dual use for a) listing all items, b) filtering to single set of items.

So the form has these items, an autogen ID (aID), another ID (bID) and some other data fields.

I''ve added a constructor overload to pass in the bID value, and I''ve added a query to the TableAdapter on the DataSet for this table, that returns values by that ID.

All that works, if I enter the data direct into to the table for example.

But if the user wants to enter a new record (using the add button of the BindingNavigator) I want to pre-fill the bID field with the value that was passed to form (if there was one), and then set that field to readonly so they can''t bork things up.

But I just can''t get it to work. I''ve tried the AddingNew, the CurrentChanged and the CurrentItemChanged events of the BindingSource...but none work. i.e. I''ve got:

serverIDTextBox.ReadOnly = false;
if (serverID != null)
{
    serverIDTextBox.Text = serverID.ToString();
    serverIDTextBox.ReadOnly = true;
}


目前在这些事件中.

刚刚发现,如果表中已经有与bID相关的数据,那么一切正常!如果没有关于bID的记录,那么它不会:(

非常困惑...


in those events currently.

Ah just found, that if I''ve got data relating to bID already in the table, then everything works! If there are no records for bID then it doesn''t:(

Very consfused...

推荐答案

如果查询中有Join,则数据源可能会自动设置为只读.

在这种情况下,您可能需要添加一个存储过程来插入数据.
If you have a Join in the query, it''s possible that the datasource automatically sets as read-only.

In that case, you may need to add a stored procedure to make the insertion of data.


这篇关于数据绑定文本框默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆