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

How to persist each rows GridViewComboBoxColumn

3 Answers 87 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Richard Harrigan
Top achievements
Rank 1
Richard Harrigan asked on 17 Apr 2013, 12:13 AM
Hi

I have a grid that starts off with no rows. The rows are created by adding to CriteriaColumnItem (see code snippet below).  When I a row the column in the new row shows the combobox column correctly.  However, when I add another row the new row shows the combobox correctly but the previous row now shows blank in the combobox column. 

Thanks
Rich


================================================================
// Used for GridViewComboBoxColumn

   public List<GroupType> TextGroupTypes = new List<GroupType>()
        {
            new GroupType {Code=4, Name="Count", },
            new GroupType {Code=1, Name="Group By", },
            new GroupType {Code=5, Name="Expression", },
            new GroupType {Code=2, Name="Min", },
            new GroupType {Code=3, Name="Max", },
            new GroupType {Code=6, Name="Where"}
        };

=============================================================================

public partial class CriteriaColumnItem
{
        public string Column { get; set; }
        public string ColumnAlias { get; set; }
        public string TableDisplayName { get; set; }
        public string SchemaName { get; set; }
        public string TableName { get; set; }
        public bool Show { get; set; }
        public string SortType{ get; set; }
        public string SortOrder { get; set; }
        public Int32 GroupByCode { get; set; }  // Used for GridViewComboBoxColumn
}

===========================================================================

<telerik:GridViewComboBoxColumn
IsFilterable="False" Width="65" Name="GroupByCode" Header="Group By"                                   
        DataMemberBinding="{Binding GroupByCode, Mode=TwoWay}"                                           
        DisplayMemberPath="Name"
        SelectedValueMemberPath="Code"  
        IsVisible="False">
</telerik:GridViewComboBoxColumn>

==============================================================================

private void radGridViewSelectedColumns_RowLoaded(object sender, RowLoadedEventArgs e)
{
CriteriaColumnItem item = e.Row.DataContext as CriteriaColumnItem;
        if (item == null)
        return;
        if(radGridViewSelectedColumns.Columns["GroupByCode"].IsVisible)
        {
        Telerik.Windows.Controls.GridViewComboBoxColumn column = 
                             radGridViewSelectedColumns.Columns["GroupByCode"] as Telerik.Windows.Controls.GridViewComboBoxColumn;
                OpenAccessHelper oaHelper = new OpenAccessHelper();
// Determine which list is needed, Only showing one for now.
                column.ItemsSource = oaHelper.TextGroupTypes;   // Is this the problem? does each row have its own itemsSource for the column
        }
}

============================================================================

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 17 Apr 2013, 06:44 AM
Hi Richard,

Why do you need to set the source on RowLoaded event? Generally, this event will be fired once a row is created and again when it recycled and reused, i.e. on scrolling. Since the source of the combo box column will be equal for all items, my recommendation will be to set it once in the initialization for example and not update it on RowLoaded. Will that approach meet your requirements ? 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Richard Harrigan
Top achievements
Rank 1
answered on 17 Apr 2013, 10:57 AM
Hi Maya,

My app calls for the contents of the combobox to change from row to row depending depending on the contents of each row.  I saw that the ItemsSourceBinding property for the ComboBox looked interesting but I wasn't sure how to code it.  If I could disable certain items in the combobox dynamically that might work?  Could the grid handle a menu instead of a combobox?

Thanks
Rich
0
Maya
Telerik team
answered on 17 Apr 2013, 11:20 AM
Hello Richard,

Indeed, the way to go if you want to have different source for each item is to work with ItemsSourceBinding. In this case the source bound to the column should be a collection property from your bisiness object.
For example, if you have Player class, it can have Clubs collection property and you can bind GridViewComboBoxColumn through ItemsSourceBinding direclty to that Clubs property. 

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Richard Harrigan
Top achievements
Rank 1
Answers by
Maya
Telerik team
Richard Harrigan
Top achievements
Rank 1
Share this question
or