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

Column header missing

3 Answers 61 Views
GridView
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 15 Jan 2009, 08:29 PM
Hello,

I'm having an issue where the column header is missing when you add a column to the grid after it has initially been created.  I have created a sample project that demonstrates my issue, but it appears I can't attach it so I included the code at the end of this post.  To reproduce it, just click on the 'Add Column' button.  Am I doing something wrong in my code or is this a bug?

In my example I'm also calling Rebind() and UpdateLayout() on the grid after adding the column because if I don't then no data appears in the column, though the column itself is added.

Note: I borrowed the Custom and Order classes from a sample app on this forum.

Thanks,

Joel


Window1.xaml
<Window x:Class="AddColumnIssue.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
    Title="Window1" Height="380" Width="701"
    <Grid> 
        <Grid.RowDefinitions> 
            <RowDefinition Height="30" /> 
            <RowDefinition Height="*" /> 
        </Grid.RowDefinitions> 
         
        <Button x:Name="AddColumnButton" Grid.Row="0" Height="23" Width="75" Click="AddColumnButton_Click" >Add Column</Button> 
         
        <telerik:RadGridView x:Name="ItemsGrid" Grid.Row="1" ItemsSource="{Binding}" AutoGenerateColumns="False" /> 
    </Grid> 
</Window> 

Window1.cs
    public partial class Window1 : Window 
    { 
        public Window1() 
        { 
            InitializeComponent(); 
            AddColumns(); 
            this.DataContext = BuildCustomers(); 
        } 
 
        private void AddColumnButton_Click(object sender, RoutedEventArgs e) 
        { 
            AddColumn(typeof(string), "Email", 200); 
            RefreshGrid(); 
        } 
 
        private void AddColumns() 
        { 
            AddColumn(typeof(int), "Number", 100); 
            AddColumn(typeof(string), "Name", 100); 
        } 
 
        private void AddColumn(Type dataType, string name, int width) 
        { 
            GridViewDataColumn column = new GridViewDataColumn(); 
            column.DataType = dataType; 
            column.HeaderText = name; 
            column.UniqueName = name; 
            column.Width = new GridLength(width); 
            column.IsReadOnly = true
 
            ItemsGrid.Columns.Add(column); 
        } 
 
        private void RefreshGrid() 
        { 
            ItemsGrid.Rebind(); 
            ItemsGrid.UpdateLayout(); 
        } 
 
        private static ObservableCollection<Customer> BuildCustomers() 
        { 
            ObservableCollection<Customer> customers = new ObservableCollection<Customer>(); 
            ObservableCollection<Order> orders = new ObservableCollection<Order>(); 
 
            for (int i = 0; i < 10; i++) 
                orders.Add(new Order { Number = i, Details = "Order" + i }); 
 
            for (int i = 0; i < 100; i++) 
                customers.Add(new Customer { Email = "Mail" + i, Name = "Name" + i, Number = i, Orders = orders }); 
 
            return customers; 
        } 
    } 

3 Answers, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 20 Jan 2009, 09:08 PM
Hi Joel,

It seems that you have stumbled upon a bug in RadGridView. We are currently investigating the problem and we will keep you updated. If that bug is a show-stopper we could send you an unofficial build, once the issue is resolved. Your telerik points have been updated accordingly.

Thanks you for your patience.

Best wishes,
Milan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
JP
Top achievements
Rank 1
answered on 21 Jan 2009, 04:54 PM
Hi Milan,

Thanks for your reply.  This is issue is not a show stopper, but I would like to be able to dynamically add columns in my app in the future.  If you could send me an unofficial build when the issue is resolved, that would be great.

Thanks,

Joel
0
Milan
Telerik team
answered on 26 Jan 2009, 07:19 PM
Hi Joel,

I'm sending you the latest SP1 build. Yu should now be able to add/remove data columns dynamically.

Kind regards,
Milan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
JP
Top achievements
Rank 1
Answers by
Milan
Telerik team
JP
Top achievements
Rank 1
Share this question
or