devxlogo

Quickly Determine Whether a Column Is Fully Visible in a DataGridView

Quickly Determine Whether a Column Is Fully Visible in a DataGridView

It’s easy to determine whether a DataGridView column is invisible—just check its Boolean Displayed property. However, the Displayed property returns True even when the column is only partially visible in the screen.

You can use the DataGridView.GetColumnDisplayRectangle method to create a solution for this problem.

The second parameter to GetColumnDisplayRectangle is called CutOverFlow, which is a Boolean value that controls whether the function returns the complete column rectangle (even if the column is not completely visible) or only the portion of the column’s rectangle that is visible.

By calling this method twice, once with CutOverFlow set to true and once with it set to false, you can create a function that compares the results and returns a Boolean value when the column is only partially visible:

Return dg.GetColumnDisplayRectangle(columnindex, False).Width = _    dg.GetColumnDisplayRectangle(columnindex, True).Width

See also  How to Avoid Money Transfer Scams  
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist