COMBOBOX bINDING DISAPPERARS ON CLICKING ON THE CELL

6 posts, 0 answers
  1. Anurag Srivastava
    Anurag Srivastava avatar
    5 posts
    Member since:
    Dec 2009

    Posted 18 Dec 2009 Link to this post

    I am trying to add a GridViewComboBoxColumn in radgridview dynmically usinfg the following code in my xaml.cs :

       GridViewComboBoxColumn comboColumn = new GridViewComboBoxColumn();
               
                comboColumn.DataMemberBinding = new Binding("CountryID");
                comboColumn.ItemsSource = GetCountries();
                comboColumn.DisplayMemberPath = "Name";
                comboColumn.UniqueName = "Name";
                comboColumn.SelectedValueMemberPath = "ID";
                this.RadGridView1.Columns.Add(comboColumn);


     private System.Collections.IEnumerable GetCountries()
            {
                List<Country> countries = new List<Country>();
                countries.Add(new Country() { ID = 0, Name = "Germany" });
                countries.Add(new Country() { ID = 1, Name = "Spain" });
                countries.Add(new Country() { ID = 2, Name = "UK" });
                return countries;
            }

    When we select some value from the combobox and move to some other cell the binding for the combobox disapperas.
    Kindly let us know your view as we are in the process of evaluating telirik radgridview control for one of our future wpf product devlopment.

    Thanks
    Anurag.


  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 19 Dec 2009 Link to this post

    Hello Anurag Srivastava,

    Thank you for the interest in our RadControls for WPF.  I have tried your code in a test project ( please find it attached. Everything seems to work OK.

    In order to find what may be causing the trouble , can you please send me your test app. I will gladly have a look and provide the fix/solution required.

    Sincerely yours,
    Pavel Pavlov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Anurag Srivastava
    Anurag Srivastava avatar
    5 posts
    Member since:
    Dec 2009

    Posted 21 Dec 2009 Link to this post

    Hi Pavel,

       Thanks for your reply.I am sending you the code so as to represent my scenario.In my xaml i have the following code:
        <Grid>
    <telerik:RadGridView x:Name="RadGridView1" AutoGenerateColumns="False" />    
        </Grid>



     In my Window1 class i have the following code:

    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using Telerik.Windows.Controls;

    namespace ComboTest_WPF
    {
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
    public Window1()
    {
    InitializeComponent();
    this.RadGridView1.ItemsSource = GetPerson();
                GridViewDataColumn textColumn = new GridViewDataColumn();
                textColumn.DataMemberBinding = new Binding("PersonName");
                textColumn.UniqueName = "PersonName";
                textColumn.Header = "PersonName";
             

    GridViewComboBoxColumn comboColumn = new GridViewComboBoxColumn();

                comboColumn.DataMemberBinding = new Binding("Name");
    comboColumn.ItemsSource = GetCountries();
                comboColumn.DisplayMemberPath = "ocountries/Name";
                comboColumn.UniqueName = "Name";
    comboColumn.Header = "Country";
                comboColumn.SelectedValueMemberPath = "Name";
                this.RadGridView1.Columns.Add(textColumn);
    this.RadGridView1.Columns.Add(comboColumn);
              
    }

            private List<Person> GetPerson()
    {
                List<Country> countries = new List<Country>();

                countries.Add(new Country() { Name = "Italy" });
                countries.Add(new Country() { Name = "Germany" });
                countries.Add(new Country() { Name = "France" });
                countries.Add(new Country() { Name = "USA" });

                List<Person> mainclass = new List<Person>();
                mainclass.Add(new Person() { PersonName = "Dave", ocountries = countries });
                mainclass.Add(new Person() { PersonName = "Robert", ocountries = countries });
                mainclass.Add(new Person() { PersonName = "Edison", ocountries = countries });
                return mainclass;
    }

    private List<Country> GetCountries()
    {
    List<Country> countries = new List<Country>();
    countries.Add(new Country() {  Name = "Italy" });
    countries.Add(new Country() {  Name = "Germany" });
    countries.Add(new Country() {  Name = "France" });
    countries.Add(new Country() {  Name = "USA" });
    return countries;
    }
    }
    public class Country
    {
    public string Name { get; set; }
    }

        public class Person
        {
            public string PersonName { get; set; }
            public List<Country> ocountries { get; set; }

        }
    }


    For each row of my person object i would like to represent the countries for that person in a GridViewComboBoxColumn.

    We are able to Bind the data with the following code but when we move to some other cell the binding disappears.
    The issue can be because of  the mismatching of the datatype . Kindly let us k-now how can we solve the following issue as we will having such scenario in our application.

    Thanks
    Anurag.





      
  5. Anurag Srivastava
    Anurag Srivastava avatar
    5 posts
    Member since:
    Dec 2009

    Posted 21 Dec 2009 Link to this post

    Sorry Pavel in the previous thread the displaymemberpath is set to :  comboColumn.DisplayMemberPath = "ocountries/Name";
    But it actually should have been set to   comboColumn.DisplayMemberPath = "Name";
    But the problems still exist after this change in the code.
  6. Anurag Srivastava
    Anurag Srivastava avatar
    5 posts
    Member since:
    Dec 2009

    Posted 23 Dec 2009 Link to this post

    Hi,
     Kindly let us know the solution for the same asap.As we are planning to  purchase the license copy of radcontrols for Wpf .But this issue seems to be a show stopper for our application.

    Awaiting for your reponse.

    Thanks
    Anurag.
  7. Tsvyatko
    Admin
    Tsvyatko avatar
    832 posts

    Posted 24 Dec 2009 Link to this post

    Hi Anurag Srivastava,

    In the provided sample code your Person class has List<Country>. However this list cannot provide information which is the selected country for each Person. Thus GridView doesn't know which value to display.
    So, to keep this information there has to be information only for one Counrty in Person class or some other field such as Id or Name that provide information about the selected Country Value.

    Please, check the attach sample project illustrating GridView usage with Country property in the Person class. You can also find detailed information about how Combobox Column works in our documentation - http://www.telerik.com/help/wpf/gridview-columns-column-types.html#GridViewComboBoxColumn

    If you have any more questions do not hesitate to contact us.

    All the best,
    Tsvyatko
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
UI for WPF is Visual Studio 2017 Ready