Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Re-sizing a DataGridView in C# based on its data contents

$
0
0

I have successfully created and filled in a DataGridView from data within our SQL Server Database.

Is there any way I can get the DataGridView itself to auto-size based on the data contents contained within it? For example, I am bringing back a Description based on a Code Value chosen within a Combo Box. Some of those descriptions are short, which is why I sized my DataGridView accordingly. However, some of the descriptions are medium...in which case I'd like my DataGridView to automatically adjust. There's room to adjust. If I make my DataGridView as wide as my widest description, then I have a lot of"gray", empty space...in which case I'd like to adjust my DataGridView down.

I have tried variuous things including some C# code within my Form.

Can someone please provide me the properties that my DataGridView should have and what the C# code is to automatically re-size the DataGridView based on the result set?

Thanks in advance for your review and am hopeful for a reply.

PSULionRP


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>