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

GridViewComboColumn binding to List<String>

2 Answers 818 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dharmavaram
Top achievements
Rank 1
Dharmavaram asked on 11 Jan 2017, 06:17 AM

Hi ,

I am binding one of the Property "Location" of  a class to Gridview column as combobox.Its ItemSource is another property in ViewModel of type List<string>.

But here the problem is I am not able to see the value of Location when Grid is loaded.The following is Xaml related to GridviewComboColumn.

 <telerik:RadGridView.Columns>
                    <telerik:GridViewComboBoxColumn  DataMemberBinding="{Binding Location}"  ItemsSource="{Binding LocationList}" IsComboBoxEditable="False"  Width="*" />               
                </telerik:RadGridView.Columns>

Here what should be the selectedValueMemberPath and DisplayMemberPath values will be ?? Location List is a simple List<string> not a class type.

How to make Location value to be seen when grid loaded?/

Regards,

Nagasree.

2 Answers, 1 is accepted

Sort by
1
Lance | Senior Manager Technical Support
Telerik team
answered on 11 Jan 2017, 04:29 PM
Hi Nagrasree,

Binding to an ItemsSource property directly depends on where your LocationList is located. If it's in the same context as the GridView, then it will work as is.

I've attached a small demo that shows how to use it in the way you'd looking for, here's a screenshot of the demo at runtime:




If your LocationList is in a different data context, you can change the binding so that it points at the correct context (or use a ValueConverter). Alternatively, you can set it directly in code, please take a look at this tutorial for full explanation of the latter approach.

If you still can't get it to work, please update my attached demo so that it replicates the problem. Then open a support ticket and attach the reproducible so that the RadGridView support team can investigate it directly.

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Dharmavaram
Top achievements
Rank 1
answered on 12 Jan 2017, 06:55 AM

Hi,

 Actually I am not able to run your Sample Application because some dll reference and other exceptions.I modified the application now it is not working in this sample application also.when we load LocationProperty is empty combobox is populating fine but Location value of respective grid not coming.

Here there is no option to attach zip file.I am inserting code below please check once

public class LocationItem
    {
        public LocationItem(string title,string Location)
        {
            this.Title = title;
            this.Location = Location;
        }
 
        private string  _title;
 
        public string  Title
        {
            get { return _title; }
            set { _title = value; }
        }
 
        private string _location;
 
        public string Location
        {
            get { return _location; }
            set { _location = value; }
        }
 
        public static ObservableCollection<LocationItem> GetItems()
        {
            ObservableCollection<LocationItem> items = new ObservableCollection<LocationItem>();
            items.Add(new LocationItem("Item1", "Location3"));
            items.Add(new LocationItem("Item2", "Location1"));
            return items;
        }
         
         
    }
public class MainViewModel : ViewModelBase
   {
       private ObservableCollection<LocationItem> gridDataSource;
       private List<string> locationList;
 
       public MainViewModel()
       {
       }
 
       public ObservableCollection<LocationItem> GridDataSource
       {
           get
           {
                
               return gridDataSource ?? (gridDataSource = LocationItem.GetItems()); }
           set { gridDataSource = value; OnPropertyChanged("GridDataSource");}
       }
 
       public List<string> LocationList
       {
           get
           {
               List<string> locationvalue = new List<string>();
               locationvalue.Add("Location 1");
                  locationvalue.Add("Location 2");
                  locationvalue.Add("Location 3");
               return locationList ?? (locationList = locationvalue); }
           set { locationList = value; OnPropertyChanged("LocationList");}
       }
   }
Tags
GridView
Asked by
Dharmavaram
Top achievements
Rank 1
Answers by
Lance | Senior Manager Technical Support
Telerik team
Dharmavaram
Top achievements
Rank 1
Share this question
or