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

Column reorder issue after hiding columns at runtime

3 Answers 138 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jaspreet
Top achievements
Rank 1
Jaspreet asked on 17 Oct 2011, 01:24 PM
Hi,

I am working on an application where I need to dynamically hide/unhide the columns. I have implemented that functionality. However, after hiding a few columns at runtime, if I try to reorder column by dragging dropping the columns, the RadGridView adds blank columns at the hidden columns' places. I have created a small sample demonstrating the issue.

Xaml File:
<Window x:Class="AbstractionPOC.Window1"
        Title="Window1" Height="500" Width="900"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
    <StackPanel>
        <ComboBox x:Name="viewFields" Grid.Column="2" ItemsSource="{Binding Columns, ElementName=orderView}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <CheckBox Content="{Binding Header}"
                          IsChecked="{Binding IsVisible, Mode=TwoWay}" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
        <telerik:RadGridView      Grid.Row="1" Grid.ColumnSpan="4" x:Name="orderView"      
                SelectionMode="Extended"  EditTriggers="None" AutoGenerateColumns="True"  >
        </telerik:RadGridView>
    </StackPanel>
</Window>

Code Behind:
using System;
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.Shapes;
using System.Collections.ObjectModel;
 
namespace AbstractionPOC
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public ObservableCollection<CustomerOrder> CustomerOrders
        {
            get;
            set;
        }
 
        public Window1()
        {
            InitializeComponent();
            CustomerOrders = new ObservableCollection<CustomerOrder>
            {
                new CustomerOrder() {CustomerName="David Blaine", CustomerPONumber="PO123", PharmacyNotes="Some Pharmacy Notes", PrescriptionNumber="12345", ProductName="Cetrizine", ShipToId=387541},
                new CustomerOrder() {CustomerName="John Ruth", CustomerPONumber="PO654", PharmacyNotes="Some Other Notes", PrescriptionNumber="67890", ProductName="Brufen", ShipToId=12387},
                new CustomerOrder() {CustomerName="Jane Doe", CustomerPONumber="PO325", PharmacyNotes="More Pharmacy Notes", PrescriptionNumber="54321", ProductName="Crocin", ShipToId=65879},
                new CustomerOrder() {CustomerName="Robert Frost", CustomerPONumber="PO698", PharmacyNotes="Some More Notes", PrescriptionNumber="19875", ProductName="Paracetamole", ShipToId=234578},
                new CustomerOrder() {CustomerName="Tim Ferriss", CustomerPONumber="PO568", PharmacyNotes="Some Notes", PrescriptionNumber="15485", ProductName="Tetracycline", ShipToId=286541},
            };
 
            orderView.ItemsSource = CustomerOrders;
        }
    }
}

CustomerOrder class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace AbstractionPOC
{
    public class CustomerOrder
    {
        public string CustomerName
        {
            get;
            set;
        }
 
        public string ProductName
        {
            get;
            set;
        }
 
 
        public string PharmacyNotes
        {
            get;
            set;
        }
 
        public string CustomerPONumber
        {
            get;
            set;
        }
 
        public string PrescriptionNumber
        {
            get;
            set;
        }
 
        public long ShipToId
        {
            get;
            set;
        }
    }
}

Now, at runtime I can show/hide a column by opening the combobox and checking/unchecking the checkbox for any column. However, after hiding the column, if I try to reorder the column, the gridview adds a blank column. For example, after hiding the CustomerPONumber column, if I drag the ShipToId column and place it after ProductName column, the gridview add a blank column after PharmacyNotes column(where the hidden column was before hiding).

Please help. All inputs are appreciated.

Thanks,
Jaspreet Singh.


3 Answers, 1 is accepted

Sort by
0
Vera
Telerik team
answered on 18 Oct 2011, 05:23 PM
Hi Jaspreet,

Unfortunately, I was not able to reproduce the described behavior. May I ask you to take a look at the attached project and at the video I captured and let me know in case I am missing something?
And can you verify that you are using version 2011.2.920?

Kind regards,
Vera
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Jaspreet
Top achievements
Rank 1
answered on 19 Oct 2011, 03:49 AM
Hi Vera,

Thanks for the reply. I am using version 2011.1.315. Let me update it to the latest version and check again.

Thanks,
Jaspreet Singh.
0
Jaspreet
Top achievements
Rank 1
answered on 19 Oct 2011, 04:21 AM
Hi Vera,

I have downloaded the latest version and this issue is resolved in that. Thanks a lot for your help.

Thanks,
Jaspreet Singh.
Tags
GridView
Asked by
Jaspreet
Top achievements
Rank 1
Answers by
Vera
Telerik team
Jaspreet
Top achievements
Rank 1
Share this question
or