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

Get property type of a property bound column

5 Answers 197 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 17 Sep 2010, 04:31 PM
Hi,

I ran into the problem that I need to get access to the type of a property bound to a column. I need to acomplish this on the AutoGeneratingColumn event.


I've manage to do it with a common grid:

private void dtgRestuls_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
        {
               var columnAttributes = ((PropertyDescriptor)e.PropertyDescriptor).Attributes.OfType<ColumnAttribute>();
               
if (columnAttributes.Count() == 0)
                {
                    e.Cancel = true;
                }
                else
                {
                    e.Cancel = !IsColumnMarkAsVisible(columnAttributes);
                }
            }

            
        }

The problem is that DataGridAutoGeneratingColumnEventArgs exposes a PropertyDescriptor property, but GridViewAutoGeneratingColumnEventArgs don't.


Anyone got any idea of where to find it on GridViewAutoGeneratingColumnEventArgs, or maybe a workaround?

Thanks!

5 Answers, 1 is accepted

Sort by
0
Jason
Top achievements
Rank 1
answered on 17 Sep 2010, 05:05 PM
Is there a reason you have to auto generate the columns?  Do you not have any idea about the type of data being bound to the gridview before runtime?
0
Daniel
Top achievements
Rank 1
answered on 17 Sep 2010, 05:18 PM
Yes, there is a reson.

I'm using WPF-MVVM.

I'm binding the grid to a property (this would be an entity) from the viewModel. I know this property implements a given interface and that its properties carry attributes that define their behaviour.

I need to bind this entity to the grid, and avoid showing certain properties as columns.

It's part of a presentation framework, so I need it to be quiet abstract and clean so the particular implementations maden with this fwk will look as simple as possible.

Thanks!
0
Daniel
Top achievements
Rank 1
answered on 17 Sep 2010, 10:52 PM
Well I manage to work around this issue by reflecting my entity from the ItemsSource grid property. Then on the AutoGeneratingColumn event I use e.Column.UniqueName to locate the property from reflected properties collection.

It's a shame that the rad control missed those useful properties related to the column.

Regards.
0
Milan
Telerik team
answered on 22 Sep 2010, 05:06 PM
Hello Daniel,

I am Glad that you have found a solution to your problem. We will consider adding the missing property to the event arguments of AutogeneratingColumn. Thank you very much for your feedback. 

I have updated your Telerik points. 


Greetings,
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
Andreas
Top achievements
Rank 1
answered on 21 Mar 2012, 12:15 PM
Hello Milan,

I have the same Problem with des missing PropertyDescriptor in the AutogeneratingColums arguments. Any news about that???

Andreas
Tags
GridView
Asked by
Daniel
Top achievements
Rank 1
Answers by
Jason
Top achievements
Rank 1
Daniel
Top achievements
Rank 1
Milan
Telerik team
Andreas
Top achievements
Rank 1
Share this question
or