x.Text 分配默认值后未更新
x.Text not updating after assigning default value to it
我使用 C# 在 VS2013 中编程。我试图修改下拉文本框 (Telerik RadDropDownListElement)。最后一次用户输入的值将是打开软件时的默认值。
我使用 Properties.Settings.Default.var 来保存用户输入。当我将它分配给 x.Text 时,我无法再访问用户在 运行 时间内输入的文本框中的值。
public Initialize()
{
/****other initial ****/
x.Text = Properties.Settings.Default.var;
// set text to default value
}
private void save_button_Click(object sender, EventArgs e)
{
Properties.Settings.Default.var = x.Text;
//x.Test still has the default value, not the value in textbox
Properties.Settings.Default.save();
}
我尝试使用来自 link 的 属性 绑定,但我得到了类似的结果。
Automatically update the Application Setting using the binding from VS.Net Designer
单击保存按钮时如何访问文本框中的值而不是默认值?
/****编辑详细信息****/
如果我注释掉
,我可以将x.Text保存到var
x.Text = Properties.Settings.Default.var;
但随后未显示默认值。
我使用下拉列表作为一个简单的文本框。这会产生重大影响吗?
我没有使用下拉列表的索引,只使用了文本。
尝试Properties.Settings.Default["mysetting"];
我想这取决于您是如何填充下拉列表的。如果它处于未绑定模式并且您手动添加了项目,则可以设置控件的文本,但如果是绑定模式,则应使用值。
但是,我建议采用不同的方法。不要设置 Text,而是设置 SelectedItem(或 SelectedIndex 属性)。要设置 SelectedItem,找到您需要 select 的项目并将其分配给 属性:
radDropDownList1.SelectedItem = radDropDownList1.FindItemExact("your string", true);
确保 FindItemExact return 是一个项目,如果不是,请检查您的项目和您保存的字符串。
您还可以使用其他几个 Find* 方法。他们return索引,可以在SelectedIndex中设置属性.
我使用 C# 在 VS2013 中编程。我试图修改下拉文本框 (Telerik RadDropDownListElement)。最后一次用户输入的值将是打开软件时的默认值。
我使用 Properties.Settings.Default.var 来保存用户输入。当我将它分配给 x.Text 时,我无法再访问用户在 运行 时间内输入的文本框中的值。
public Initialize()
{
/****other initial ****/
x.Text = Properties.Settings.Default.var;
// set text to default value
}
private void save_button_Click(object sender, EventArgs e)
{
Properties.Settings.Default.var = x.Text;
//x.Test still has the default value, not the value in textbox
Properties.Settings.Default.save();
}
我尝试使用来自 link 的 属性 绑定,但我得到了类似的结果。 Automatically update the Application Setting using the binding from VS.Net Designer
单击保存按钮时如何访问文本框中的值而不是默认值?
/****编辑详细信息****/
如果我注释掉
,我可以将x.Text保存到var
x.Text = Properties.Settings.Default.var;
但随后未显示默认值。
我使用下拉列表作为一个简单的文本框。这会产生重大影响吗?
我没有使用下拉列表的索引,只使用了文本。
尝试Properties.Settings.Default["mysetting"];
我想这取决于您是如何填充下拉列表的。如果它处于未绑定模式并且您手动添加了项目,则可以设置控件的文本,但如果是绑定模式,则应使用值。
但是,我建议采用不同的方法。不要设置 Text,而是设置 SelectedItem(或 SelectedIndex 属性)。要设置 SelectedItem,找到您需要 select 的项目并将其分配给 属性:
radDropDownList1.SelectedItem = radDropDownList1.FindItemExact("your string", true);
确保 FindItemExact return 是一个项目,如果不是,请检查您的项目和您保存的字符串。
您还可以使用其他几个 Find* 方法。他们return索引,可以在SelectedIndex中设置属性.