TZacks-2728 avatar image
0 Votes"
TZacks-2728 asked karenpayneoregon commented

c# winform: datagridview and column width and PC resolution

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.

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

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

image.png (28.6 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TZacks-2728 avatar image TZacks-2728 karenpayneoregon ·

Madam thanks a lot for your link. from the link you shared i found 3 guide lines but not sure does it solve my problem or not?
point 1
if i add this manifest
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<!-- Windows 10 compatibility -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />

point 2
Enable per-monitor DPI awareness in the app.config file.
<add key="DpiAwareness" value="PerMonitorV2" />

point 3

 static void Main()
     Application.Run(new Form2());

if i follow above 3 point does it solve my problem ? my datagridview column width getting different & scrollbar is coming when run application in lower resolution.
My pc resolution is 1920 X 1080 where datagridview column width is fine but the moment i run in my colleague pc resolution is 1366 X 768 there scrollbar is coming. please tell me if i follow above 3 points then datagridview column width would looks same in any resolution.

waiting for your next suggestion. Thanks

0 Votes 0 ·

Don't have any other recommendations. When I worked with Windows forms in an environment with mixed resolutions I always used the lower resolution. Moving to WPF solves these issues but requires a decent understanding of how to make a window responsive to resolutions similar to what BootStrap does for web apps with custom media breakpoints and proper classes e.g. container and flex usage (which of course does not help here).

Sorry I don't have other recommendations.

0 Votes 0 ·

1 Answer

ELBANNOUNIMOHAMMED-6711 avatar image
0 Votes"
ELBANNOUNIMOHAMMED-6711 answered karenpayneoregon commented

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@ELBANNOUNIMOHAMMED-6711 Since this is an English speaking forum please post in English

1 Vote 1 ·