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

[Solved] Header ContextMenu gone after setting ItemsSource

4 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael
Top achievements
Rank 1
Michael asked on 28 May 2009, 02:55 PM
Hi

I am attempting to create a ContextMenu on the header of a RadGridView. Using your demo I was able to go get the context menu attached and working.

However when I attempted to recreate this in my own solution it appeared that it did not work. After some investigation I found out that it was infact working... that is until the ItemSource property is set on the RadGridView, at which point the ContextMenu no longer shows, and the standard "Silverlight" option pops up instead.

I tested this theory with your Head ContextMenu demo.

by changing:

 

public Example()

 

{

 

this.InitializeComponent();

 

RadGridView1.ItemsSource =

new MyBusinessObjects().GetData(100);

 

}


to this: (in effect, delaying the load of data until after the ContextMenu is setup)

 

public Example()

 

{

 

this.InitializeComponent();

 

 

//RadGridView1.ItemsSource = new MyBusinessObjects().GetData(100);

 

 

this.Loaded += new RoutedEventHandler(Example_Loaded);

 

}

 

private void Example_Loaded(object sender, RoutedEventArgs e)

 

{

 

this.Dispatcher.BeginInvoke(new Action(() =>

 

{

 

RadGridView1.ItemsSource =

new MyBusinessObjects().GetData(100);

 

}));

}


Is there a fix or work around for this issue?

~Michael

4 Answers, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 30 May 2009, 11:22 AM
Hi Michael,

Check out this updated version of the example posted in another forum thread. It should do the work for your case.

Hope this helps.

Kind regards,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Michael
Top achievements
Rank 1
answered on 01 Jun 2009, 02:30 PM
Thanks Stefan,

I was able to get the desired results by setting the ItemsSource of the RadGridView to an ObservableCollection in the constructor of my page, and then alter the collection when ever I wanted to update the GridView instead of setting the ItemsSource property again.

~Michael
0
Michael
Top achievements
Rank 1
answered on 01 Jun 2009, 07:42 PM
Hello again,

I have run into another issue with the HeaderContext menus. The ContextMenus are now disappearing when the ColumnLayout is changed. (example: move a columnHeader around by dragging and dropping it, or reorder them in code)

I checked the sample solution you linked me to, and this is also the case, changing the order of the columns causes the ContextMenus to stop appearing when right clicking the headers.

~Michael
0
Michael
Top achievements
Rank 1
answered on 01 Jun 2009, 09:04 PM
Ok,

After some testing and trying different things I think I have come up with a way to that will allow me to detect when the columns change. And then, when they do, I remove the ContextMenus from the old ColumnHeaderCells, then just readd the ContextMenus to the new Headers. Timing is key here, and I just kind of guessed as to what Dispatcher I needed to invoke to make sure the GridViewHeaderRow has time to be populated with the new GridViewHeaderCells.

Hopefully there isn't some case where this doesn't work. Also, if there is a better design, please let me know.

~Michael

Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Michael
Top achievements
Rank 1
Share this question
or