The problem I am having is that I am creating a ContextMenu on the GridViewHeaderRow where I list the column header text with checkboxes so the user can select which ones to display. When I assign the column.Header with text directly, obviously all I have to do is loop through and get column.Header; however when I don't assign the Header, and let the GridView figure the text by using the DisplayAttribute.ShortName of the bound data members, the column.Header is null. I know the text must be somewhere, but I can't find it.
Is there some way to determine the ShortName from the GridViewColumn in this scenario?
Thanks in advance,
Steve
Is there some way to determine the ShortName from the GridViewColumn in this scenario?
Thanks in advance,
Steve
7 Answers, 1 is accepted
0
Hi Steve,
Didie
the Telerik team
As I understand you would like to show a header ContextMenu with an option to select the columns to be displayed. If this is the case, then I would suggest you to check the "Header Context Menu" WPF demo.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
0

Steve
Top achievements
Rank 1
answered on 04 Dec 2012, 04:58 PM
Hi Didie, As a matter of fact that is the code I am using. If you read my post more carefully, you'll see that my problem involves getting the header text when the Header is not explicitly assigned and is created by the GridView using the DisplayAttribute.ShortName assigned to the bound data member. In this case when the following code executes the column.Header is null.
Please reread my original post and advise.
Thanks in advance,
Steve
.
RadMenuItem subMenu = new RadMenuItem();
subMenu.Header = column.Header;
subMenu.IsCheckable = true;
subMenu.IsChecked = true;
Please reread my original post and advise.
Thanks in advance,
Steve
0
Hello Steve,
Have you tried to access the UniqueName of the Column instead? I believe it should have the correct text.
Kind regards,
Didie
the Telerik team
Have you tried to access the UniqueName of the Column instead? I believe it should have the correct text.
Kind regards,
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
0

Steve
Top achievements
Rank 1
answered on 10 Dec 2012, 08:57 PM
I tried using the UniqueName field; however as you can see from the attached image and the following class definition, UniqueName contains the actual property name and not the DisplayAttribute.ShortName, whereas the column headers use the ShortName. Perhaps there is some other method I could use to access the correct text.
Thanks in advance,
Steve
Thanks in advance,
Steve
public class Person
{
[Display(ShortName = "First Name")]
public String FirstName
{
get;
set;
}
[Display(ShortName = "Last Name")]
public String LastName
{
get;
set;
}
[Display(AutoGenerateFilter = false, AutoGenerateField = false)]
public String FullName
{
get;
set;
}
[Display(ShortName = "Email")]
public String Email
{
get;
set;
}
[Display(ShortName = "Employed by AccountMate")]
public bool Employee
{
get;
set;
}
[Display(ShortName = "Last Contact")]
public DateTime LastContact
{
get;
set;
}
public Person(String fn, String ln, String em, bool empl, DateTime lc)
{
FirstName = fn;
LastName = ln;
Email = em;
Employee = empl;
LastContact = lc;
}
}
0
Hi,
Vlad
the Telerik team
Have you tried Header property of the column?
Kind regards,Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
0

Steve
Top achievements
Rank 1
answered on 11 Dec 2012, 05:19 PM
Vlad - Read my original post.
0

Steve
Top achievements
Rank 1
answered on 11 Dec 2012, 09:31 PM
I figured out what the problem is. The version of GridViewHeaderMenu.cs that I was using initialized the menu on the grid.RowLoaded event
The problem with this implementation is that the grid is not completely initialized at that point. As a matter of fact if AutoGenerateColumns is true, the grid.Columns collection is empty when the RowLoaded event is fired. By switching to the grid.Loaded event, all is good.
Thanks for your help,
Steve
private void RowLoaded(object sender, RowLoadedEventArgs e)
{
if (e.Row is GridViewHeaderRow)
{
InitializeMenus((GridViewHeaderRow) e.Row);
}
}
The problem with this implementation is that the grid is not completely initialized at that point. As a matter of fact if AutoGenerateColumns is true, the grid.Columns collection is empty when the RowLoaded event is fired. By switching to the grid.Loaded event, all is good.
Thanks for your help,
Steve