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

Problem with Combobox inside RadGridView

1 Answer 98 Views
GridView
This is a migrated thread and some comments may be shown as answers.
kalyan gupta
Top achievements
Rank 1
kalyan gupta asked on 12 Aug 2010, 10:14 AM
Hi @
I am using Telerik RadGridView in which I have a drop down in side CellEditTemplate and a TextBlock inside DataTemplate of CellTemplate.
When I change the value in Dropdown, it should be reflected back to the Text of Textblock. But it is not happening in my case.

Following is the code to reproduce the problem I am facing.

public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            radGridView1.ItemsSource = this.BindDataGrid();
        }
        private void radGridView1_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
        {
            if (e.EditOperationType == GridViewEditOperationType.Insert)
            {
                ((ComboItemsCollections)(((sender as RadGridView).CurrentCell as GridViewCell).ParentRow.DataContext)).IsRowModified = "INSERT";
            }
            else
            {
                if ((sender as RadGridView).CurrentCell != null && !((ComboItemsCollections)(((sender as RadGridView).CurrentCell as GridViewCell).ParentRow.DataContext)).IsRowModified.ToString().Equals("INSERT"))
                    ((ComboItemsCollections)(((sender as RadGridView).CurrentCell as GridViewCell).ParentRow.DataContext)).IsRowModified = "UPDATE";
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pstrSelectedProgram"></param>
        private List<ComboItemsCollections> BindDataGrid()
        {
            List<ComboItemsCollections> llstCmbItemColl;
            ComboItemsCollections lobjCmbItemColl;
            llstCmbItemColl = new List<ComboItemsCollections>();
            try
            {
                for (int i = 0; i < 10; i++)
                {
                    lobjCmbItemColl = new ComboItemsCollections();
                    lobjCmbItemColl.ComboboxColumn = "Comboitem 1";
                    llstCmbItemColl.Add(lobjCmbItemColl);
                }
            }
            catch (Exception ex)
            {
  
            }
            return llstCmbItemColl;
        }
    }
    public class ComboItemsCollections
    {
        List<InnerComboItems> _lstInnerComboItems;
        public ComboItemsCollections()
        {
  
        }
        public InnerComboItems[] InnerComboItemsCollection
        {
            get
            {
                _lstInnerComboItems = new List<InnerComboItems>();
                InnerComboItems obj;
                for (int i = 0; i < 10; i++)
                {
                    obj = new InnerComboItems();
                    obj.ComboItem = "Comboitem " + (i + 1).ToString();
                    _lstInnerComboItems.Add(obj);
                }
                return _lstInnerComboItems.ToArray();
            }
        }
  
        public string IsRowModified { get; set; }
  
        public string ComboboxColumn { get; set; }
    }
    public class InnerComboItems
    {
        string pstrComboItem;
        public string ComboItem
        {
            get { return pstrComboItem; }
            set { pstrComboItem = value; }
        }
        public InnerComboItems()
        {
            pstrComboItem = "";
        }
    }

<Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadGridView FrozenColumnCount="5" FontFamily="Arial"  AutoGenerateColumns="False" HorizontalAlignment="Left" Name="radGridView1" VerticalAlignment="Top" 
                             Height="380" Margin="10,10,10,0" RowEditEnded="radGridView1_RowEditEnded" CanUserDeleteRows="True">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Combobox Column" >
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <TextBlock Name="txtComboText" Text="{Binding ComboboxColumn}" />
                            </Grid>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.CellEditTemplate>
                        <DataTemplate>
                            <ComboBox ItemsSource="{Binding InnerComboItemsCollection}" SelectedItem="{Binding ComboboxColumn}" DisplayMemberPath="ComboItem">
                            </ComboBox>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>

Please let me to solve the problem.

Thanks in advance
Kalyan Gupta

1 Answer, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 13 Aug 2010, 03:06 PM
Hi kalyan gupta,
I would highly recommend to use the GridViewCombobox column , instead of trying to achieve this with a regular column .

Looking at your code , I thing this should solve most of the problems , and will make things achievable with less code.

Regards,
Pavel Pavlov
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
Tags
GridView
Asked by
kalyan gupta
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Share this question
or