Is there an event that gets fired when one clicks the ColumnHeader of a Datagrid to trigger a sort on that column ?
Thanks in advance
DataGridColumnHeader is a control itself so you should be able to assign an handler to its MouseLeftButtonDown event programatically.
Related
I attached event "DataGridColumnHeader_MouseRightButtonDown" on Loaded event to open context menu to display column names. It's working fine.
private void dtaGrd_Loaded(object sender, RoutedEventArgs e)
{
columnHeaders = TreeHelper.GetVisualChildCollection<DataGridColumnHeader>(this);
foreach (DataGridColumnHeader columnHeader in columnHeaders)
{
columnHeader.MouseRightButtonDown += DataGridColumnHeader_MouseRightButtonDown;
}
}
But when I uncheck column then Visibility of "Name" column to be Collapsed. Again, I checked that column to set Visibility to "Visible" then "DataGridColumnHeader_MouseRightButtonDown" event is not working.
Is my Implementation is wrong or DataGridColumnHeader will create new instance when visibility is change?
Yes, I found that when visilbity of DataGridColumnHeader is changed then it's Loaded event is also fires. So, We have to bind even handlers on loaded event of DataGridColumnHeader.
On which event of datagrid I come to know that DataGridColumnHeader is Loaded ?
Or Where I have to attach DataGridColumnHeader Loaded Event ?
First, you should be known that each time you change visibility of any control, its 'Loaded' event executes.
Here in your case, you're providing handlers to the column headers of the datagrid by finding from visual collection of the DataGrid.
So, once you flip Visibility of the column from Visible to Collapsed it'll unload column from datagrid and again, when you make it Visible it loads with default style provided to the header.
And here comes the main problem that handlers you binded to the column Header will not be found as column got Reset
My opinion is to give try to Custom Commands or you've to manage attaching/detaching handlers while fliping visibility.
Thanks :)
Have Radgrid which have Cellvaluechanged Event
after bind list as grid datasource The Cellvaluechanged doesn't fire ?
rgv_AlternativItem.DataSource = S.ListAlternatives;
rgv_AlternativItem.Refresh();
CellValueChanged should not fire when you rebind the grid. To detect this moment, you can use the DataBindingComplete event.
I have a datagrid to which I bind some items. I only allow selecting rows (single item) on this grid.
This grid has a DataGridCheckBoxColumn and a SelectionChanged event.
The problem is that when the user presses a checkbox, it also selects the row (and triggers the SelectionChanged event). This is not the behaviour I would like.
Is there a way I can either prevent the SelectionChanged event from triggering when pressing the checkbox OR detect if was the checkbox column that was pressed in the selectionchanged event?
Thanks!
What about adding a Mouse_Click event on DataGrid row and if it's original source is Checkbox then set e.handled = true otherwise go ahead.
I have a MainWindow with 3 main buttons at the top and below a MainUserControl.
In the MainUserControl I have at top 3 UserControls with ButtonBars
and at the bottom a DataGrid.
When I enter data in a DataGridCell and I click into another cell a property change is fired in my ViewModel bound to the DataGrid.
When I enter data... and I click on one of the 3 main buttons again a property change is fired because of Lost Focus event.
When I ... and I click on one of the buttons in the ButtonBar in the UserControl no property change is fired because there seem to be no Lost Focus event.
How can I fix that?
FocusManager.IsFocusScope="False" on the UserControl or other elements like Menu solved the problem and my property changes are raised now in the model :)
If you change your binding to to set UpdateSourceTrigger=PropertyChanged then you will not need to rely on the LostFocus to do a property update.
Is there a "BeforeSelectionChanged" event for the combobox? I want to verify some stuff before the SelectedItem property changes.
There's no PreviewSelectionChanged event. Instead of using two way binding, use one way binding to SelectedItem and get updates through command or SelectionChanged event. That way you can in the handler do some verification and even fake a cancel of the selection.
I don't think that there is, unfortunately.
You might be able to use the PreviewLeftMouseDown event and determine if the mouse is over an item in the ComboBox. If it is over an item that isn't the SelectedItem, you know it is about to change.