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

Combo Boxes in Edit mode

3 Answers 29 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Srujana
Top achievements
Rank 1
Srujana asked on 02 Mar 2011, 05:22 PM
Hello,

I was just looking at the demo that you have here. I was just wondering if we can add an item "Add New" at the end  along with all other items that comes from my database so we can add new item if the item that we need doesn't exist(mostly needed when we create new row), and then when the "Add New" is selected I need to populate a popup window that has all the fields needed to create that new item, By the time I close the popup the items is created and then when I close it, the new item is pre selected.

Please let me know if it is doable, if you have any code sample or demo that does that I would certainly appriciate it.

Thanks,
Srujana.

3 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 06 Mar 2011, 02:15 AM
Hello Srujana,

 What you can do is add a handler to RadComboBox's SelectionChanged event:
this.radGridView1.AddHandler(RadComboBox.SelectionChangedEvent, new Telerik.Windows.Controls.SelectionChangedEventHandler(comboSelectionChanged));

Then, in the event handler (the comboSelectionChanged method) check if the newly selected item is the special "Add New" item you have previously added to the collection the RadComboBox is bound to. If it is, display a popup that allows the user to create a new item and when the popup is closed (the Closed event fires), add the new item to the combo's source collection and set the SelectedItem of the combo to the new item.

All the best,
Yavor Georgiev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Srujana
Top achievements
Rank 1
answered on 07 Mar 2011, 04:53 PM
Hi Yavor,

Thanks for your response, I am failing to add item for "Add New" at the end of my list in combobox, I am first binding the data to the combo using my RIA service, then I make an attempt to create a combobox item and then set it content to "Add New" and then add it to the combo box, it fails with the error, "Operation not supported on read-only collection.

here is my code in XAML:

 

 

 

<telerik:RadComboBox x:Name="XXXCombo" ItemsSource="{Binding}" DisplayMemberPath="Name" SelectedValuePath="Id" SelectionChanged="XXXCombo_SelectionChanged" Width="240" ClearSelectionButtonVisibility="Visible" CanKeyboardNavigationSelectItems="True" IsEditable="True" IsReadOnly="False" TextSearchMode="StartsWith" CanAutocompleteSelectItems="True" ClearSelectionButtonContent="Clear Selection" EmptyText=" --Select XXX-- " Margin

="0,10,0,0" />

 

 


And in code behind:

XXXCombo.DataContext = context.XXX;

context.Load(context.GetXXXQuery().OrderBy(o => o.Name));

 

RadComboBoxItem comboBoxItem=new RadComboBoxItem(); 

 

 

comboBoxItem.Content=

 

"Add New...";

 

 

XXXCombo.Items.Add(comboBoxItem);

 

 


It works fine if I don't add the "ADD NEW " at the end.

Please let me know if you see anything missing here.

Thanks,
Srujana.
0
Kjell
Top achievements
Rank 1
answered on 07 Mar 2011, 07:53 PM
Hi Srujana, since the radComboBox has a datacontext, I think you need to add the new item there instead of to the actual box directly. 

I'm not sure what yours looks like but say you are using an observable collection for example, you could do something like this:

ObservableCollection<whatever> oc = (ObservableCollection<whatever>)XXXCombo.ItemsSource;
oc.Add(new whatever);

I could be wrong but it's worth a try.
Tags
GridView
Asked by
Srujana
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Srujana
Top achievements
Rank 1
Kjell
Top achievements
Rank 1
Share this question
or