c# winform: datagridview and column width and PC resolution

T.Zacks 3,986 Reputation points
2022-05-26T16:11:44.62+00:00

My pc resolution is 1920 X 1080 and my colleague pc resolution is 1366 X 768
so when form run in my pc and datagridview comes then no scrollbar is coming but when the same program run in my colleague pc then scrollbar is coming for datagridview. here is a screen shot.
205923-image.png

scrollbar is coming when application is running under the resolution 1366 X 768 .
i also mention column width in my code like this way

                dgList.Columns[0].Width = 125;  
                dgList.Columns[1].Width = 560;  
                dgList.Columns[2].Width = 86;  
                dgList.Columns[3].Width = 73;  
                dgList.Columns[4].Width = 93;  

i have checked out few write up for how make winform resolution independent solution. here are the links

https://stackoverflow.com/questions/185804/how-to-control-the-font-dpi-in-net-winforms-app
https://stackoverflow.com/questions/22735174/how-to-write-winforms-code-that-auto-scales-to-system-font-and-dpi-settings
https://www.sgrottel.de/?p=1581&lang=en
https://stackoverflow.com/questions/4075802/creating-a-dpi-aware-application
https://www.telerik.com/blogs/winforms-scaling-at-large-dpi-settings-is-it-even-possible-
https://stackoverflow.com/questions/22735174/how-to-write-winforms-code-that-auto-scales-to-system-font-and-dpi-settings?noredirect=1&lq=1
https://stackoverflow.com/questions/13228185/how-to-configure-an-app-to-run-correctly-on-a-machine-with-a-high-dpi-setting-e?noredirect=1&lq=1
https://stackoverflow.com/questions/185804/how-to-control-the-font-dpi-in-net-winforms-app?noredirect=1&lq=1
https://stackoverflow.com/questions/26073635/windows-forms-dpi-scaling?noredirect=1&lq=1
https://stackoverflow.com/questions/20209905/making-an-existing-net-windows-application-to-be-dpi-aware?noredirect=1&lq=1

but still things not clear how to make a application resolution independent.

please tell me how to design column width for datagridview as a result it always should looks same when run in any resolution.
please guide me. Thanks

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,247 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ELBANNOUNI.MOHAMMED 81 Reputation points
    2022-05-28T12:15:37.197+00:00

    Il existe deux types de dimensionnement automatique dans le contrôle DataGridView : le mode de remplissage de colonne et le dimensionnement automatique basé sur le contenu.

    En mode de remplissage de colonne, les colonnes visibles du contrôle remplissent la largeur de la zone d’affichage du contrôle. Pour plus d’informations sur ce mode, consultez Mode de remplissage de colonne dans le contrôle DataGridView Windows Forms.

    Vous pouvez également configurer des lignes, des colonnes et des en-têtes pour ajuster automatiquement leur taille en fonction du contenu de leur cellule. Dans ce cas, l’ajustement de la taille se produit chaque fois que le contenu de la cellule change.