Options in DataFormComboBoxField

4 posts, 0 answers
  1. Alan
    Alan avatar
    4 posts
    Member since:
    Jul 2016

    Posted 22 Sep Link to this post

    Hello,

    I am trying to implement a RadDataForm using a DatFormComboBoxField. Following this section of documentation: http://docs.telerik.com/devtools/wpf/controls/raddataform/how-to/raddatafor-edit-lookup-values-with-radcombobox

    I have been unable to produce results. 

    I stumbled across the ability to use an enum within a class to allow all of the enum's values to be combo box items. Sadly, as our combobox options will be changing based on our database, this won't be an effective solution. Are there any similar methods to add options to a combo box (dictionary, json object, etc)?

    This has been a struggle for a few days now, any help is greatly appreciated...

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 27 Sep Link to this post

    Hello Alan,

    I have prepared a sample project, demonstrating how you can set up a DatFormComboBoxField and also update its ItemsSource during runtime. Could you please have a look at it and let me know whether such an approach would be applicable in your scenario? 

    If that is not the case please provide more information on the exact setup at your end so that I may better assist you in finding a solution to your issue. Specifying the class structure at hand would definitely be of help.

    I will be awaiting your reply.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Alan
    Alan avatar
    4 posts
    Member since:
    Jul 2016

    Posted 27 Sep in reply to Dilyan Traykov Link to this post

    Dilyan,

    Thanks for the response. I believe the section that keeps messing me up is the RadDataForm_AutoGeneratingField.

    I followed another tutorial on this as well and its use keeps eluding me, as i am new with wpf and C#.  I'm not quite sure what falls into the paths or propertynames. My Class that the form is based on is:

     

    using MongoDB.Bson;
    using System;
    using System.Collections.Generic;
    using MongoDB.Driver;
    using MongoDB.Bson.Serialization;
    using Newtonsoft.Json;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.IO;
    using System.Net;
    using System.Text;

    namespace IntegrateWithRadGridView
    {
        public class Job :IEditableObject, INotifyPropertyChanged
        {
            JobData backupJobData;
            public string custName;
            public string contactName;
            public string email;
            public string phone;
            public string address;
            public string scheduledBeginDate;
            public string scheduledEndDate;
            public string realBeginDate;
            public string realEndDate;
            public string creator;
            public string user;
            //public serviceRep handyman;
            public int idJob;
            public int idCustomer;
            public string description;
            public string newnote;
            public string oldnotes;
            public ObjectId _id;
            public ObservableCollection<Combo> combos;

            public struct JobData
            {
                internal string custName;
                internal string contactName;
                internal string email;
                internal string phone;
                internal string address;
                internal string scheduledBeginDate;
                internal string scheduledEndDate;
                internal string realBeginDate;
                internal string realEndDate;
                internal string creator;
                internal string user;
                //internal serviceRep handyman;
                internal int idJob;
                internal int idCustomer;
                internal string description;
                internal string newnote;
                internal string oldnotes;
                internal ObjectId _id;
                internal ObservableCollection<Combo> combos;
            }

            public Job()
            {

            }

            public Job(string cuname, string coname, string em, string ph, string add, string sbegin, string send, string rbegin, string rend, 
                string cr, string us, int idJ, int idC, string des)
            {
                this.backupJobData = new JobData();
                this.backupJobData.custName = cuname;
                this.custName = cuname;
                this.backupJobData.contactName = coname;
                this.contactName = coname;
                this.backupJobData.email = em;
                this.email = em;
                this.backupJobData.phone = ph;
                this.phone = ph;
                this.backupJobData.address = add;
                this.address = add;
                this.backupJobData.scheduledBeginDate = sbegin;
                this.ScheduledBeginDate = sbegin;
                this.backupJobData.scheduledEndDate = send;
                this.scheduledEndDate = send;
                this.backupJobData.realBeginDate = rbegin;
                this.realBeginDate = rbegin;
                this.backupJobData.realEndDate = rend;
                this.realEndDate = rend;
                this.backupJobData.creator = cr;
                this.creator = cr;
                this.backupJobData.user = us;
                this.user = us;
                this.backupJobData.idJob = idJ;
                this.idJob = idJ;
                this.backupJobData.idCustomer = idC;
                this.idCustomer = idC;
                this.backupJobData.description = des;
                this.description = des;
            }

            [Display(Name = "Customer Name")]
            public string CustName
            {
                get
                {
                    return custName;
                }
                set
                {
                    custName = value;
                    NotifyPropertyChanged("CustName");
                }
            }
            [Display(Name = "Contact Name")]
            public string ContactName
            {
                get
                {
                    return contactName;
                }
                set
                {
                    contactName = value;
                    NotifyPropertyChanged("ContactName");
                }
            }
            [Display(Name = "Customer Address")]
            public string Address
            {
                get
                {
                    return address;
                }
                set
                {
                    address = value;
                    NotifyPropertyChanged("Address");
                }
            }
            [Display(Name = "Customer Phone")]
            public string Phone
            {
                get
                {
                    return phone;
                }
                set
                {
                    phone = value;
                    NotifyPropertyChanged("Phone");
                }
            }
            [Display(Name = "Customer Email")]
            public string Email
            {
                get
                {
                    return email;
                }
                set
                {
                    email = value;
                    NotifyPropertyChanged("Email");
                }
            }
            [Display(Name = "Scheduled Begin Date")]
            public string ScheduledBeginDate
            {
                get
                {
                    return scheduledBeginDate;
                }
                set
                {
                    scheduledBeginDate = value;
                    NotifyPropertyChanged("ScheduledBeginDate");
                }
            }
            [Display(Name = "Scheduled End Date")]
            public string ScheduledEndDate
            {
                get
                {
                    return scheduledEndDate;
                }
                set
                {
                    scheduledEndDate = value;
                    NotifyPropertyChanged("ScheduledEndDate");
                }
            }
            [Display(Name = "Real Begin Date")]
            public string RealBeginDate
            {
                get
                {
                    return realBeginDate;
                }
                set
                {
                    realBeginDate = value;
                    NotifyPropertyChanged("RealBeginDate");
                }
            }
            [Display(Name = "Real End Date")]
            public string RealEndDate
            {
                get
                {
                    return realEndDate;
                }
                set
                {
                    realEndDate = value;
                    NotifyPropertyChanged("RealEndDate");
                }
            }
            [Display(Name = "Job Description")]
            public string Description
            {
                get
                {
                    return description;
                }
                set
                {
                    description = value;
                    NotifyPropertyChanged("Description");
                }
            }
            [Display(Name = "Handyman")]
            public ObservableCollection<Combo> Combos
            {
                get
                {
                    if (this.combos == null)
                    {
                        this.combos = Combo.GetCombo();

                    }
                    return this.combos;
                }
            }
            



            public void BeginEdit()
            {

            }
            public void CancelEdit()
            {
                CustName = this.backupJobData.custName;
                ContactName = this.backupJobData.contactName;
                Address = this.backupJobData.address;
                Phone = this.backupJobData.phone;
                Email = this.backupJobData.email;
                ScheduledBeginDate = this.backupJobData.scheduledBeginDate;
                ScheduledEndDate = this.backupJobData.scheduledEndDate;
                RealBeginDate = this.backupJobData.realBeginDate;
                realEndDate = this.backupJobData.realEndDate;
                Description = this.backupJobData.description;
            }

            public void EndEdit()
            {
                this.backupJobData.custName = CustName;
                this.backupJobData.contactName = ContactName;
                this.backupJobData.address = Address;
                this.backupJobData.phone = Phone;
                this.backupJobData.email = Email;
                this.backupJobData.scheduledBeginDate = ScheduledBeginDate;
                this.backupJobData.scheduledEndDate = ScheduledEndDate;
                this.backupJobData.realBeginDate = RealBeginDate;
                this.backupJobData.realEndDate = RealEndDate;

                ***Other DB and Http Request Calls***


            
            
            public event PropertyChangedEventHandler PropertyChanged;

            private void NotifyPropertyChanged(string info)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
    }

     

    The combo class is just an int to link to a string of a service rep's name.

     

    Any help is greatly appreciated

  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 28 Sep Link to this post

    Hello Alan,

    From what I understood from your previous reply, you're not autogenerating RadDataForm's fields but defining data templates for the ReadOnlyTemplate and EditTemplate properties, am I correct?

    If that is the case, here's the code from my previous reply, translated into XAML:

    <DataTemplate x:Key="MyTemplate">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <telerik:DataFormDataField Label="Name" DataMemberBinding="{Binding Name, Mode=TwoWay}" />
            <telerik:DataFormComboBoxField Grid.Row="1"
                                           Label="Country"
                                           DataMemberBinding="{Binding CountryID, Mode=TwoWay}"
                                           ItemsSource="{Binding Countries, Source={StaticResource MyViewModel}}"
                                           SelectedValuePath="ID"
                                           DisplayMemberPath="Name"/>
        </Grid>
    </DataTemplate>
    <telerik:RadDataForm x:Name="radDataForm" AutoGenerateFields="False" ReadOnlyTemplate="{StaticResource MyTemplate}" EditTemplate="{StaticResource MyTemplate}" CurrentItem="{Binding Clubs[0]}" />

    For your convenience, I'm also attaching the modified version of the project. Of course, you will need to adjust this to work with the setup you have at your end.

    Do let me know how this goes.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top