在ComboBox中添加默认项

时间:2016-01-26 12:30:55

标签: c# silverlight combobox

我想在绑定后在NSMutableDictionary* params =[NSMutableDictionary dictionaryWithObjectsAndKeys:command, @"command", _nicknameTextField.text = fldUsername.text, @"username", hashedPassword, @"password", nil ]; $stmt = $this->pdo->prepare('INSERT INTO active_users (user_Id, device_token, nickname, secret_code, ip_address) VALUES (?, ?, ?, ?, ?)'); $stmt->execute(array($userId, $token, $name, $code, $_SERVER['REMOTE_ADDR'])); 添加默认项。我试着这样做:

Combobox

但得到了错误:

  

只读集合不支持的操作

0th Index ComboBox中添加默认项目的方式是什么?

1 个答案:

答案 0 :(得分:1)

<强> BUT

我假设你正在使用WPF和XAML试试这个:

WPF Combobox DefaultValue (Please Select)

<ComboBox SelectedIndex="0">
    <ComboBox.ItemsSource>
        <CompositeCollection>
            <ListBoxItem>Please Select</ListBoxItem>
            <CollectionContainer Collection="{Binding Source={StaticResource YOURDATASOURCE}}" />
        </CompositeCollection>
    </ComboBox.ItemsSource>
</ComboBox>

但是

如果你正在使用Silverlight,就​​像你说的那样:

使用:NotSelectedText="--Select Products--"

<local:ExtendedComboBox ItemsSource="{Binding ...Whatever...}" NotSelectedText="--Select Products--" />

源代码:local:ExtendedComboBox已开启:

https://vortexwolf.wordpress.com/2011/04/05/silverlight-combobox-prompt-text-if-an-item-isnt-selected/

Silverlight: Default value in Combobox

Alterntive

创建带有文本ProductType的默认"--Select Products--",然后添加到colection oj位置0;

e.Result.Add(new ProductType { Text =" --Select Products-- " });

cboProductType.ItemsSource = e.Result;

类似的东西。