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

Default values of RadComboBox in a DataForm

10 Answers 169 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Johan Van der Galien
Top achievements
Rank 1
Johan Van der Galien asked on 23 Mar 2011, 02:23 PM

Hi,

There seems to be no simple way of setting the defaults of radcomboboxes in a dataform?

The dataform is databound to the ddsWerkInkomen domaindatasource. I want in case the CurrentItem is new, empty and still unused that only then the combo’s should have a default value set, to make filling in the forms easier for the users

private void ddsWerksituatie_LoadingData(object sender, LoadingDataEventArgs e)
       {
           if (this.ddsWerksituatie.DataView.CurrentItem == null)
           {
               this.DivbCbx.SelectedIndex = 0;
           }
       }

The above code has the effect that the combobox settings cannot be updated by saving to the database, they always keep the default value in the database, as set in code. Without the above code updating and saving works fine, but I would like to have also default values.
 

Johan.

10 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 29 Mar 2011, 12:32 PM
Hello Johan Van der Galien,

I've attached a simple example demonstrating how you can set default value in AddingNewItem event handler of the dataform. Please download the example and give it a try.

Hope it helps.

All the best,
Yana
the Telerik team
0
Almond
Top achievements
Rank 1
answered on 12 Aug 2011, 03:33 AM
Hello Yana,

Good morning.

Your sample below is very interesting. I would just like to ask if you the same can be implemented in cascading RadComboBoxes. Basically, I have already populated the ComboBoxes with the records from the tables however i am at lost on how to reference the RadComboBoxes inside a RadDataForm the codebehind.  I want to select the 1st Record that was returned from tables. Please see scenario below:

tables:
tblCompany
tblDepartment
tblSections

As i said I have successfully binded the RadComboBoxes with their respective tables and has also fitlered them based on the selectedValue of the RadComboBox.  I just really want to know how can i do a reference to the companyCbo, departmentCbo and sectionCbo in order for me to throw the .SelectedIndex = 0; command.   One more thing interesting things is that when i place the RadCombBoxes outside the form, it actually work because i can see the companyCbo, departmentCbo and sectionCbo objects and then throw the .SelectedIndex = 0 based on the SelectionChanged of the objects.  Can you please direct me on how to reference objects inside a data form.  I have been looking for blogs and forums for solutions and i am now in my 4th day of looking for solutions :(

Hope you can help me in my dilemma and thanks in advance.

almond
0
Yana
Telerik team
answered on 12 Aug 2011, 12:51 PM
Hello Almond,

I would suggest to check the DataForm CurrentItem property instead ( in the example it should be of type Person) and update the property to which the SelectedValue of the ComboBox is bound. If you have TwoWay binding the change will be reflected in the UI.

Please try this approach and let us know whether it suits your needs.

All the best,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Almond
Top achievements
Rank 1
answered on 14 Aug 2011, 09:32 AM
Hello Yana,

Much thanks for the help.  However, i think this is not the solution that i need.  What i really need is to reference an object inside a RadDataForm and that object is a RadComboBox.  Then i want its list filtered based on the 1st combobox selectedvalue. As i have mentioned i have successfuly filtered all the RadcomboBox that i have.  I would really want to have its value to be the 1st record of the combobox and be displayed as a default in any event of a selection changed on the related comboboxes.
Scenario being i have 2 tables the Company and the Department.  For each company they have corresponding departments. Once the CompanyComboBox changed, it will trow a filtering action to the Database  based on the SelectedValue of the CompanyComboBox.  The 1st record of those filtered results is what i want to display as the initial value of the DepartmentComboBox.

I hope you can help me with what I really would like to do.

Thanks in advance.
0
Konstantina
Telerik team
answered on 22 Aug 2011, 08:35 AM
Hello Almond,

In order to achieve your goal you can just set the SelectedIndex property of the DepartmentComboBox to 0. Just make sure that the ItemsSource is set after all items are loaded.

Hope this helps.

Regards,
Konstantina
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Almond
Top achievements
Rank 1
answered on 22 Aug 2011, 09:10 AM
Hello Konstantina,

I have already did that and still i am not able to get the ComboBox to the 1st Item.  It seems that the Loaded event of the DataSource is firing multiple number of times and i am not sure where to capture the last triggering event of the Loaded event.

For the time being I am settling on having it blank until someone can point me out on how to go about it.  I am really sure how come i can get the reference of the ComboBox in the SelectedChanged event of the the combo but not inside the Loaded event of the DataSource.

Is there a way in Silverlight to check if all the items area already loaded? Particularly the DataSource.

Thanks again in advance.

almond
0
Konstantina
Telerik team
answered on 24 Aug 2011, 02:25 PM
Hi Almond,

You can assign a x:Name to the ComboBox, and in that way you will be able to get its reference in the Loaded event of the DataSource. Then, set there the ItemsSource of the ComboBox and the SelectedItem property should work correctly.

Please let us know if that worked for you.

All the best,
Konstantina
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Almond
Top achievements
Rank 1
answered on 26 Aug 2011, 01:56 AM
Hello Konstantina,

Good morning.
I am little bit new to silverlight.  Do you have any sample codes of your suggestions.  I always put an x:Name to all of my controls so that I can it as reference.

Can you post a code on how to go about your suggestion.

Thanks in advance.

almond
0
Yana
Telerik team
answered on 31 Aug 2011, 01:26 PM
Hi Almond,

You cannot access the other comboboxes by their x:Name when they're placed in a DataForm, we're sorry for the confusion.

I've modified the example to show you how you can implement cascading comboboxes by updating the properties in the ViewModel, please download it and examine it.

Best wishes,
Yana
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Almond
Top achievements
Rank 1
answered on 31 Aug 2011, 05:37 PM
Hello Yana,

Much thanks for the sample file.  I will try it first thing in the morning. This will be the first time i will try a viewmodel as i have always use the EF generated by sillverlight.

Can it be done in EF?

Thanks and good day once again.

regards,
almond
Tags
ComboBox
Asked by
Johan Van der Galien
Top achievements
Rank 1
Answers by
Yana
Telerik team
Almond
Top achievements
Rank 1
Konstantina
Telerik team
Share this question
or