问题描述
我无法为未绑定的组合框设置默认的组合框所选的值。这是我的代码:
I cannot set the default combobox selected value for an unbound combobox. Here is my code:
System.Console.WriteLine("Current Tag Org Id = " + CurrentTag.Org.OrgId);
ddlRUC.SelectedValue = CurrentTag.Org.OrgId;
System.Console.WriteLine("ddlRUC selected value = " + ddlRUC.SelectedValue);
以下是输出结果:
当前标签组织Id = 285
ddlRUC选择值=
Here is the output:Current Tag Org Id = 285ddlRUC selected value =
请注意,ddlRUC.SelectedValue尚未设置为285.为了使用SelectedValue属性,数据源是否需要绑定?
Note that ddlRUC.SelectedValue has not been set to 285. Does the datasource need to be bound in order to use the SelectedValue property? If so, how do I set the default item shown in a combobox that is not bound?
推荐答案
SelectedValue属性只能工作为数据列表框。如果您可以在列表<>中创建列表项,您可以将列表绑定到控件,并且SelectedValue将按您的需要工作。
The SelectedValue property will only work for a databound listbox. If you can create your list items in a List<>, you can then bind the list to the control and SelectedValue will work as you would like.
这篇关于Windows.Form组合框无法设置未绑定控件的SelectedValue属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!