This is a migrated thread and some comments may be shown as answers.

How to set the default value

2 Answers 611 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 15 Sep 2012, 04:18 PM
Hi..
I have the following ComboBox using a data template.. I'm trying to set the default value to a selection.
When the page loads the selection is blank.
I've tried 


  // BIND
  var queryConf = from c in DC.conferences
                            orderby c.name descending
                            select c;
                        
        this.cmbConf.ItemsSource = queryConf.ToList();

// Set DEFAULT
  this.cmbConf.SelectedItem = queryConf.ToList()[1];
   this.cmbConf.Text = (queryConf.ToList()[1] as conference).name;

but the selection is still blank. !!!

I have also tried

this.cmbConf.SelectedIndex = 1;


How can I set the default value and show the values? 
What am I doing wrong.
thx again


 ///  COMBOBOX

    <telerikInput:RadComboBox  TabIndex="6"  Name="cmbConf" telerik:TextSearch.TextPath="name" 
                                 FontWeight="Bold" telerikControls:StyleManager.Theme="Vista"
                                 SelectedValue="{Binding Path=id}"  SelectedValuePath="id" Width="332" >
                    
                        <telerikInput:RadComboBox.ItemTemplate>
                            <DataTemplate>
                                <Grid Margin="5" Width="300">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>
                                    <TextBlock FontWeight="Bold" FontSize="14" x:Name="txtConf"  Text="{Binding name}" />
                                    <TextBlock Foreground="Navy" Grid.ColumnSpan="3" Grid.Row="1" Text="{Binding name_alt}" />


                                    <StackPanel Orientation="Horizontal" Grid.Row="2" Margin="0,0,0,0">


                                        <TextBlock Foreground="Navy" Margin="5,0,0,0" Text="{Binding first_day, StringFormat=d}" />
                                        <TextBlock Foreground="Navy" Margin="5,0,0,0" Text=" - " />
                                        <TextBlock Foreground="Navy" Margin="5,0,0,0" Text="{Binding last_day, StringFormat=d}" />


                                    </StackPanel>


                                </Grid>
                            </DataTemplate>
                        </telerikInput:RadComboBox.ItemTemplate>
                    </telerikInput:RadComboBox>

2 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 19 Sep 2012, 10:44 AM
Hi Jon,

I noticed that you've set both SelectedValuePath and SelectedValue properties -  this means that you should have a property id which needs to be set to the id property of the default value.

The other options are to remove these properties and set SelectedItem or SelectedIndex.  I have attached a sample project showing all the approaches. Also you could check this help article for more information about selection.

Hope this helps.

Greetings,
Yana
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Jon
Top achievements
Rank 1
answered on 19 Sep 2012, 02:32 PM
thanks again!
Tags
ComboBox
Asked by
Jon
Top achievements
Rank 1
Answers by
Yana
Telerik team
Jon
Top achievements
Rank 1
Share this question
or