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

Combobox inside the DataForm

4 Answers 193 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 04 Jul 2011, 09:19 PM
I need to use a drop down combobox inside a DataForm, so that the user can select an item from it.
I use a ViewModel to get the details from the database as well as to save the users entered data.

Like this:
public NewClientViewModel()
{
    if (!DesignerProperties.IsInDesignTool)
    {
        EntityQuery<VisibilityType> getVisibiltyTypesQuery = _context.GetVisibilityTypesQuery();
        _visibilityTypes = new QueryableDomainServiceCollectionView<VisibilityType>(_context, getVisibiltyTypesQuery);
        _visibilityTypes.AutoLoad = true;
                    }
}
       public void LoadClients(int groupId)
{
    _groupId = groupId;
    EntityQuery<Organisation> getOrganisationsByGroupIdQuery = _context.GetOrganisationsByGroupIdQuery(_groupId);
    _organisations = new QueryableDomainServiceCollectionView<Organisation>(_context, getOrganisationsByGroupIdQuery);
    _organisations.AutoLoad = true;
    _organisations.SubmittedChanges += new System.EventHandler<Telerik.Windows.Controls.DomainServices.DomainServiceSubmittedChangesEventArgs>(_organisations_SubmittedChanges);
     }
private QueryableDomainServiceCollectionView<Organisation> _organisations;
public IEnumerable Organisations
{
    get { return _organisations; }
}
       private QueryableDomainServiceCollectionView<VisibilityType> _visibilityTypes;
public IEnumerable VisibilityTypes
{
    get { return _visibilityTypes; }
}
private Organisation _newOrganisation;
public Organisation NewOrganisation
{
    get { return _newOrganisation; }
    set
    {
        if (value != _newOrganisation)
        {
            _newOrganisation = value;
        }
    }
}

i inject the view model to page like this:
public NewClient(int groupId)
        {
            InitializeComponent();
  
            NewClientViewModel _viewModel = new NewClientViewModel();
  
            _viewModel.LoadClients(groupId);
  
            this.DataContext = _viewModel;
        }

and my control looks like this:
<telerik:RadDataForm Header="New Client" AutoGenerateFields="False" CurrentItem="{Binding NewOrganisation}" CommandButtonsVisibility="None" AutoEdit="True" AutoCommit="True" BorderThickness="0">
                <telerik:RadDataForm.ReadOnlyTemplate>
                    <DataTemplate>
                        <StackPanel>
                                                    </StackPanel>
                    </DataTemplate>
                </telerik:RadDataForm.ReadOnlyTemplate>
                <telerik:RadDataForm.EditTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <telerik:DataFormDataField DataMemberBinding="{Binding Details.Name, Mode=TwoWay}" Label="Client Name:"/>
                            <telerik:DataFormDataField DataMemberBinding="{Binding Details.Description, Mode=TwoWay}" Label="Description:"/>
                            <telerik:DataFormDataField DataMemberBinding="{Binding WebSite, Mode=TwoWay}" Label="Web Site:"/>
                            <telerik:DataFormDataField DataMemberBinding="{Binding Details.Notes, Mode=TwoWay}" Label="Notes:"/>
                            <telerik:DataFormComboBoxField DataMemberBinding="{Binding VisibilityTypeId, Mode=TwoWay}" Label="Visibility:" DisplayMemberPath="Name" SelectedValuePath="Id" ItemsSource="{Binding VisibilityTypes}" />
                                                   </StackPanel>
                    </DataTemplate>
                </telerik:RadDataForm.EditTemplate>
            </telerik:RadDataForm>

Problem i am having is that once i have bound the DataForm to NewOrganisation, i can no longer bind the combobox to the VewTypes as they are not part of the NewOrganisation but rather on the same 'level' in me viewmodel.

How would you do this? What is the correct way of using DataForm in this case?

4 Answers, 1 is accepted

Sort by
0
Accepted
Pavel Pavlov
Telerik team
answered on 06 Jul 2011, 05:04 PM
Hi Andrew,

Indeed the context inside the form would be the current item , not the entire view model.

The standard approach here is:

To be able to access a property of the view model , you may expose it (the view model )  as a static resource on the page.
Then in the ItemsSource binding for the combo field , use binding to this static resource.

In case  you have troubles implementing this  feel free to send me a small runnable repro with your objects, and I will implement the missing part (binding the combo)  for you.

Best wishes,
Pavel Pavlov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Andrew
Top achievements
Rank 1
answered on 12 Jul 2011, 02:59 PM
Thank you Pavel,

I have already solved this, by getting help from the silverlight forum.
http://forums.silverlight.net/forums/p/233501/573475.aspx#573475

0
Vikash
Top achievements
Rank 1
answered on 29 Dec 2011, 03:44 PM
Hi Povel,

I am new to Telerik,MVVM controls

I am working in a new module of my project and I have following requirment:
1. Many textboxes, drop down, tab controls etc
2. Conditional data binding is required in dropdown and tab controls
3. single record at a time

Our XAML: I am using radDataForm

Can you share a sample project implementing MVVM using radDataForm, in terms of drop down binding, conditional dropdown data binding (like: add values two columns of database table "value1:Value2")

Also, how I can place multiple buttons in  arow of radDataForm' grid.Row (or any other option)

Thanks

0
Maya
Telerik team
answered on 30 Dec 2011, 08:19 AM
Hi Vikash,

I would recommend you to look at this article illustrating how you can define DataFormComboBoxField in your RadDataForm. 
Considering defining buttons in the control, it may be achievable by editing the template of RadDataForm. However, in order to suggest any further, I would need a bit more details - where do you want to place those buttons, do you want to remove the current ones with your own ? 

Regards,
Maya
the Telerik team

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

Tags
DataForm
Asked by
Andrew
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Andrew
Top achievements
Rank 1
Vikash
Top achievements
Rank 1
Maya
Telerik team
Share this question
or