Hi there
We are using the UltraWinGrid v19.1.20191.379 in a C# WinForm .NET 4.6.2 app and I am noticing some strange behaviour with the standard inbuilt ColumnChooser on a dual screen setup.
The application is typically maximized to the full size of one of the 2 monitors but the ColumnChooser is always being displayed on the LHS monitor regardless of which monitor is being used to display the applications window.
I can use the PC's display settings to a rearrange the order of the display but it has no affect, the column chooser is always displayed on the LHS monitor.
Is there an appropriate property\configuration to ensure the column chooser is always displayed over the owning grid control.
Regards
Geoff
Hi again
I should point out that the LHS Monitor is Monitor 1 of the 2 monitors, so the column chooser is always displayed on Monitor 1 regardless of which monitor the hosting application is being displayed on.
Hope that makes sense
Hello Geoff
Thanks for your post.It looks like a bug. The ColumnChooser remember the last location the used put it. So if it comes up on the wrong monitor and they move it to the current monitor, it will henceforth display where they moved it for the life of the application. But the initial display doesn’t take the location of the owning form into account.
I will log this issue to our development department and continue to follow as the support case. Please kindly take care of our notice.In the meantime, you can work around it like so:
private void UltraGrid1_BeforeColumnChooserDisplayed(object sender, BeforeColumnChooserDisplayedEventArgs e) { var screen = Infragistics.Win.Utilities.ScreenFromRectangle(this.Bounds); if (!screen.Bounds.Contains(e.Dialog.Bounds)) { e.Dialog.Shown += Dialog_Shown; } } private void Dialog_Shown(object sender, EventArgs e) { var dialog = (Form)sender; dialog.Shown -= Dialog_Shown; var screen = Infragistics.Win.Utilities.ScreenFromRectangle(this.Bounds); dialog.DesktopBounds = new Rectangle( screen.Bounds.X, screen.Bounds.Y, dialog.Bounds.Width, dialog.Bounds.Height ); }
Sincerely,Motoki.
Hi Motoki
Unfortunately that does not work, still always showing the column chooser on the main primary display\screen.
Hm, okay... I just looked at this again, and it looks like the Shown event only fires the FIRST time a form is shown. So this will work the first time, but if you moved your main form around from one monitor to another, it will not work on any subsequent showing of the ColumnChooser dialog. So I changed it to use VisibleChanged of the form, instead, and that seems to work better. Here is the updated code and a working sample project.
private void UltraGrid1_BeforeColumnChooserDisplayed(object sender, BeforeColumnChooserDisplayedEventArgs e) { var screen = Infragistics.Win.Utilities.ScreenFromRectangle(this.Bounds); if (!screen.Bounds.Contains(e.Dialog.Bounds)) { e.Dialog.VisibleChanged += Dialog_VisibleChanged; } } private void Dialog_VisibleChanged(object sender, EventArgs e) { var dialog = (Form)sender; dialog.VisibleChanged -= Dialog_VisibleChanged; if (!dialog.Visible) return; var screen = Infragistics.Win.Utilities.ScreenFromRectangle(this.Bounds); dialog.DesktopBounds = new Rectangle( screen.Bounds.X, screen.Bounds.Y, dialog.Bounds.Width, dialog.Bounds.Height ); }
Hi Mike
That works but it's probably not ideal in that it places the column chooser in the top RHS of the screen rather than above/adjacent to the grid requesting the display of the column chooser, in a situation that a screen has multiple grids the display of the column chooser for all grids in the top RHS of the screen is a bit confusing.
None the less we can at least now display on the appropriate screen.
Thanks
Well... the code in the Dialog_VisibleChanged event is positioning the dialog on the screen. I chose the top left just arbitrarily and you could adjust that however you want. It's hard for to do any more than that, since I really don't know where you want the dialog to appear.
You could position the dialog relative to the position of the grid on the screen, of course. But that would require a lot of extra jumping through hoops to make sure the dialog is still on the screen. So you might have to try positioning is to the left or right or whatever until you find a spot where it fits on the same screen as the grid. Also, if you are going to do that, it probably makes sense to do it always, even if the grid is on the primary monitor. Otherwise, it will look weird that the dialog is positioned relative to the grid only when it's NOT on the primary monitor.
So the only tricky part of that approach is that you have to get the Rect of the grid on the screen, and that's easy enough to do using the RectangleToScreen method of the grid's parent control. So you could do something like this:
private Rectangle gridScreenRect; private void UltraGrid1_BeforeColumnChooserDisplayed(object sender, BeforeColumnChooserDisplayedEventArgs e) { var grid = (UltraGrid)sender; this.gridScreenRect = this.GetControlScreenRect(grid); e.Dialog.VisibleChanged += Dialog_VisibleChanged; } private void Dialog_VisibleChanged(object sender, EventArgs e) { var dialog = (Form)sender; dialog.VisibleChanged -= Dialog_VisibleChanged; if (!dialog.Visible) return; var screen = Infragistics.Win.Utilities.ScreenFromRectangle(this.Bounds); dialog.DesktopBounds = new Rectangle( gridScreenRect.X - dialog.Bounds.Width, gridScreenRect.Y, dialog.Bounds.Width, dialog.Bounds.Height ); } private Rectangle GetControlScreenRect(Control control) { var parentControl = control.Parent; if (null != parentControl) return control.Parent.RectangleToScreen(control.Bounds); return Rectangle.Empty; }
This code positions the dialog to the left of grid. But like I said, you will probably have to modify this code to ensure that the dialog ends up on the same screen as the grid. This code won't work very well if the grid is close to the left edge of the screen, for example, since the dialog will ends up running off the screen to the left in that case. So you might want to try left, right, and then maybe if neither of those ends up on the screen, you would have to make the dialog overlap the grid to some extent.
5226.MemDataTable CS.zip
Actually, it looks like you can simplify the workaround a lot by simply setting the dialog.StartPosition.
private void UltraGrid1_BeforeColumnChooserDisplayed(object sender, BeforeColumnChooserDisplayedEventArgs e) { var dialog = e.Dialog; var screen = Infragistics.Win.Utilities.ScreenFromRectangle(this.Bounds); if (!screen.Bounds.Contains(dialog.Bounds)) { dialog.StartPosition = FormStartPosition.WindowsDefaultLocation; dialog.DesktopBounds = new Rectangle( screen.Bounds.X, screen.Bounds.Y, dialog.Bounds.Width, dialog.Bounds.Height ); } }