Hi,In my grid, where user click con column header I want to manage both sorting and column selection.
Column selection shoud be activate when user press Alt key and click on the column header. Otherwise only with header click grid should sort the column.
This is my code, default grid setting are for sorting columns.
private void grid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { UltraGrid grid = (UltraGrid)sender; UIElement element = grid.DisplayLayout.UIElement.LastElementEntered; Infragistics.Win.UltraWinGrid.ColumnHeader columnHeader = element.GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader)) as Infragistics.Win.UltraWinGrid.ColumnHeader; if (columnHeader == null) return; if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt) { columnHeader.Column.SortIndicator = SortIndicator.Disabled; grid.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Select; } else { if (columnHeader.Column.SortIndicator == SortIndicator.Disabled) columnHeader.Column.SortIndicator = SortIndicator.Ascending; grid.Selected.Columns.Clear(); grid.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.SortMulti; } }
It woks but not perfectly. For exmple when the first time click on header pressing Alt, the sort indicator is removed but the selection on column is not visible. Now if I only click on header (without Alt key pressed) grid sort the column and now show the selection on column.
What should I do to achieve the desired behavior?
Thank you vey much
Hello Andrea,
I have been investigating into the behavior you are looking to achieve, and I have a couple of recommendations for you on this matter.
The first is to set the HeaderClickAction property on your UltraGrid.DisplayLayout.Override to one of the sort-related options, since that will be the default, no-modifier click.
The second in this case would be to add your ColumnHeader to the grid’s Selected.Columns collection after setting the HeaderClickAction to “Select.” This will select the column, and rather than the first click making the sort indicator disappear, this will happen at the same time.
I am attaching a sample project to demonstrate. Please let me know if you have any other questions or concerns on this matter.
UltraGridColumnClickDemo.zip
Thank you very much!