Question

Users So I have different users that are using different resolutions due to eyesight / preferences, whatever.

Form One of the C# forms that comes up has a datagridview with AutoSizeColumnsMode set to Fill. I realize from the reading of the object in MSDN that with Fill you cannot use the left-right scroll bar.

Problem So the problem is when the datagridview loads. The columns look great on the high resolution and fill the datagridview all the way to its borders as it should. On the lower resolution screen, some columns are hidden and must be stretched by the user to view, since the scroll bar is not enabled with the Fill option.

Attempts I tried DisplayedCells option which does give the user the scroll bar on the lower resolution and it looks / works great. But on the higher resolution, it leaves large gaps between the last column and the border of the Datagridview and looks unfinished / broken.

Question How can I say "Set to Fill unless the user is using really low resolution, then use DisplayedCells?"

Was it helpful?

Solution

You could get the resolution by

        int screenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
        int screenHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;

And then use an if-clause to set AutoSizeColumnsMode-Property.

Like this:

    private void getScreenResolution()
    {
        int screenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
        int screenHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
    }

    private void setAutoSizeColumnsMode()
    {
        if (screenWidth <= 1680 || screenHeight  <= 768)
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
        else
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top