Default values of RadComboBox in a DataForm

11 posts, 0 answers
  1. Johan Van der Galien
    Johan Van der Galien avatar
    6 posts
    Member since:
    Mar 2010

    Posted 23 Mar 2011 Link to this post

    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.

  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 29 Mar 2011 Link to this post

    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
  3. DevCraft banner
  4. Almond
    Almond avatar
    43 posts
    Member since:
    Feb 2011

    Posted 11 Aug 2011 Link to this post

    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
  5. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 12 Aug 2011 Link to this post

    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 >>

  6. Almond
    Almond avatar
    43 posts
    Member since:
    Feb 2011

    Posted 14 Aug 2011 Link to this post

    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.
  7. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 22 Aug 2011 Link to this post

    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 >>

  8. Almond
    Almond avatar
    43 posts
    Member since:
    Feb 2011

    Posted 22 Aug 2011 Link to this post

    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
  9. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 24 Aug 2011 Link to this post

    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 >>

  10. Almond
    Almond avatar
    43 posts
    Member since:
    Feb 2011

    Posted 25 Aug 2011 Link to this post

    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
  11. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 31 Aug 2011 Link to this post

    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 >>

  12. Almond
    Almond avatar
    43 posts
    Member since:
    Feb 2011

    Posted 31 Aug 2011 Link to this post

    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
Back to Top
DevCraft banner