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

GridViewComboBoxColumn Selected Value

9 Answers 374 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Avi Avni
Top achievements
Rank 1
Avi Avni asked on 24 Jun 2010, 07:23 AM
Hi,
is there Selected Value in the GridViewComboBoxColumn ?
Best regards
Ehud

9 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 24 Jun 2010, 07:24 AM
Hi,

 There is no such property since it can be different for every row. 

All the best,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Avi Avni
Top achievements
Rank 1
answered on 24 Jun 2010, 08:15 AM

So how can I get the value of the selected value?


Best Regards
Ehud
0
Vlad
Telerik team
answered on 24 Jun 2010, 08:17 AM
Hi,

 The recommended approach is MVVM. You just bind the column to desired property of your object and if the object is INotifyPropertyChanged you will get PropertyChange event raised.

Greetings,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Gauri
Top achievements
Rank 1
answered on 30 Jun 2010, 08:35 AM
How to implement code for that? can you please explain it in detail?
0
Milan
Telerik team
answered on 30 Jun 2010, 08:42 AM
Hi Gauri,

You can check out this nice blog post which demonstrates not INotifyPropertyChanged is used.


Best wishes,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Parvinder Singh
Top achievements
Rank 1
answered on 03 Sep 2010, 08:44 AM
Eventhough it is implemented notify property changed it is not showing the desired value for Region.

  GridViewComboBoxColumn comboColumn = new GridViewComboBoxColumn();
        comboColumn.Header = "Location";
        comboColumn.DataMemberBinding = new Binding { Path = new PropertyPath("LocationID"), Mode = BindingMode.TwoWay };
        BindingOperations.SetBinding(comboColumn, GridViewComboBoxColumn.ItemsSourceProperty, b);
        comboColumn.DisplayMemberPath = "Region";
        comboColumn.SelectedValueMemberPath = "ID";

All the properties are INotifiyPropertyChange is implemented.

LocationID is one of the property from Grid's Itemsource.
Region and ID are the properties from  ComboBoxColumn's ItemSource.

We got the example from following link:
http://www.telerik.com/help/wpf/gridview-gridviewcomboboxcolumn.html

We are using 2010.1.422.1040 for GridView (SilverLight).
0
Maya
Telerik team
answered on 07 Sep 2010, 12:59 PM
Hello Parvinder Singh,

Please give us more details about your exact scenario so that we could provide you with an appropriate solution and sample project if needed. Basically, you can find the "LocationID" for the item you need and afterwards to find the value displayed -  "Region" by using a converter. 
However, if that does not correspond to your requirements, we would need more information for your application.

Best wishes,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Parvinder Singh
Top achievements
Rank 1
answered on 07 Sep 2010, 04:49 PM
Hi,

I had created 2 sample solution files but i cant able to upload it.
twowayboundcombocolumn_NotWorking : In this project i m trying to achieve functionality of twowayboundcombocolumn_Working project with textboxes & buttons in MVVM 


Anyway XAML Code for twowayboundcombocolumn_NotWorking is as follows:

<UserControl x:Class="TwoWayBoundComboColumn.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input">
    <Grid x:Name="LayoutRoot" Loaded="LayoutRoot_Loaded">
        <Grid DataContext="{Binding modifiedData}">
            <dataInput:Label Height="22" HorizontalAlignment="Left" Margin="60,26,0,0" Name="label1" VerticalAlignment="Top" Width="35" Content="ID" />
            <TextBox Height="23" Text="{Binding ID, Mode=TwoWay}" HorizontalAlignment="Left" Margin="110,24,0,0" Name="textBox1" VerticalAlignment="Top" Width="126" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" />
            <dataInput:Label Content="Country ID" Height="22" HorizontalAlignment="Left" Margin="289,26,0,0" Name="label2" VerticalAlignment="Top" Width="93" />
            <TextBox Height="23" Text="{Binding CountryID, Mode=TwoWay}" HorizontalAlignment="Left" Margin="385,24,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" />
            <Button Content="Save" Height="23" HorizontalAlignment="Left" Margin="430,64,0,0" Name="saveButton" VerticalAlignment="Top" Width="75" Click="saveButton_Click" />
        </Grid>
        <Grid>
            <telerik:RadGridView x:Name="RadGridView1"  ItemsSource="{Binding locations}" AutoGenerateColumns="False" Margin="0,110,0,0">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewComboBoxColumn DataMemberBinding="{Binding CountryID, Mode=TwoWay}" DisplayMemberPath="Name" SelectedValueMemberPath="ID"  />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding ID, Mode=TwoWay}"  Width="100"  ></telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding CountryID, Mode=TwoWay}"  Width="100"  ></telerik:GridViewDataColumn>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
        </Grid>
    </Grid>
</UserControl>

C# Code for twowayboundcombocolumn_NotWorking is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace TwoWayBoundComboColumn
{
    public partial class MainPage : UserControl
    {
        //ObservableCollection<Location> locations;
        TestViewModel viewModel = new TestViewModel();
        public MainPage()
        {
            InitializeComponent();
            this.Countries = new ObservableCollection<Country>();
          
            Countries.Add(new Country() { ID = 0, Name = "USA" });
            Countries.Add(new Country() { ID = 1, Name = "Italy" });
            Countries.Add(new Country() { ID = 2, Name = "Germany" });


            //this.RadGridView1.ItemsSource = viewModel.locations;
            ((GridViewComboBoxColumn)this.RadGridView1.Columns[0]).ItemsSource = this.Countries;
        }

        public ObservableCollection<Country> Countries
        {
            get;
            set;
        }

        public ObservableCollection<Location> GetLocations()
        {
            ObservableCollection<Location> locations = new ObservableCollection<Location>();

            locations.Add(new Location() { ID = 1, CountryID = 0 });
            locations.Add(new Location() { ID = 2, CountryID = 1 });
            locations.Add(new Location() { ID = 3, CountryID = 2 });

            return locations;
        }

        private void saveButton_Click(object sender, RoutedEventArgs e)
        {

            viewModel.locations.Add(viewModel.modifiedData);
            //Countries.Add(new Country() { viewModel.modifiedData.ID, viewModel.modifiedData. });            
        }

        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            GetLocations();
        }
    }

    public class TestViewModel
    {
        public Location modifiedData = new Location();
        public ObservableCollection<Location> locations;
        public ObservableCollection<Country> countries;
    }


    public class Location : INotifyPropertyChanged
    {
        private int id;
        private int countryID;
        public int ID
        {
            get
            { return id; }
            set { id = value; NotifyPropertyChanged("ID"); }
        }
        public int CountryID { get { return countryID; } set { countryID = value; NotifyPropertyChanged("CountryID"); } }

        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public class Country
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
}

XAML Code of project twowayboundcombocolumn_Working (Functionality i m trying to achieve) is as follows:
<UserControl x:Class="TwoWayBoundComboColumn.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
  <Grid x:Name="LayoutRoot">
        <telerik:RadGridView x:Name="RadGridView1"  AutoGenerateColumns="False" Margin="0,0,0,0">
            <telerik:RadGridView.Columns>
                <telerik:GridViewComboBoxColumn DataMemberBinding="{Binding CountryID, Mode=TwoWay}" DisplayMemberPath="Name" SelectedValueMemberPath="ID"  />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding LocationID, Mode=TwoWay}"  Width="100"  ></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding CountryID, Mode=TwoWay}"  Width="100"  ></telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>
</UserControl>

C# Code for twowayboundcombocolumn_Working is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace TwoWayBoundComboColumn
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            this.Countries = new ObservableCollection<Country>();

            Countries.Add(new Country() { ID = 0, Name = "USA" });
            Countries.Add(new Country() { ID = 1, Name = "Italy" });
            Countries.Add(new Country() { ID = 2, Name = "Germany" });


            this.RadGridView1.ItemsSource = GetLocations();
            ((GridViewComboBoxColumn)this.RadGridView1.Columns[0]).ItemsSource = this.Countries;
        }

        public ObservableCollection<Country> Countries
        {
            get;
            set;
        }

        private ObservableCollection<Location> GetLocations()
        {
            ObservableCollection<Location> locations = new ObservableCollection<Location>();

            locations.Add(new Location() { LocationID = 1, CountryID = 0 });
            locations.Add(new Location() { LocationID = 2, CountryID = 1 });
            locations.Add(new Location() { LocationID = 3, CountryID = 2 });

            return locations;
        }
    }

    public class Location : INotifyPropertyChanged
    {
        private int id;
        private int countryID;
        public int LocationID
        {
            get
            { return id; }
            set { id = value; NotifyPropertyChanged("LocationID"); }
        }
        public int CountryID { get { return countryID; } set { countryID = value; NotifyPropertyChanged("CountryID"); } }

        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public class Country
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
}

Thanx in advance.
Please Share your feedback..




0
Parvinder Singh
Top achievements
Rank 1
answered on 08 Sep 2010, 07:35 AM
Hi,

Its working :).

Thanx. 
Tags
GridView
Asked by
Avi Avni
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Avi Avni
Top achievements
Rank 1
Gauri
Top achievements
Rank 1
Milan
Telerik team
Parvinder Singh
Top achievements
Rank 1
Maya
Telerik team
Share this question
or