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

COMBOBOX bINDING DISAPPERARS ON CLICKING ON THE CELL

5 Answers 83 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Anurag Srivastava
Top achievements
Rank 1
Anurag Srivastava asked on 18 Dec 2009, 04:45 PM
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.


5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 19 Dec 2009, 09:10 AM
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.
0
Anurag Srivastava
Top achievements
Rank 1
answered on 21 Dec 2009, 11:40 AM
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.





  
0
Anurag Srivastava
Top achievements
Rank 1
answered on 21 Dec 2009, 11:44 AM
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.
0
Anurag Srivastava
Top achievements
Rank 1
answered on 23 Dec 2009, 12:08 PM
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.
0
Tsvyatko
Telerik team
answered on 24 Dec 2009, 08:09 AM
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.
Tags
ComboBox
Asked by
Anurag Srivastava
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Anurag Srivastava
Top achievements
Rank 1
Tsvyatko
Telerik team
Share this question
or