Ticket T522313
Visible to All Users

GridView - Where in code the BestFitColumns method can be invoked

created 8 years ago

[DevExpress Support Team: CLONED FROM Q139901: Apply Best Fit for all columns]
Where should I put the BestFit method?

Answers approved by DevExpress Support

created 8 years ago (modified 8 years ago)

You can invoke this method in any place of the target container.
For instance, if you need to apply best fit to columns before the grid is shown, you can handle the Load event in the following manner:

C#
private void Load(object sender, EventArgs e) { gridControl1.ForceInitialize(); gridView1.BestFitColumns(); }

Since GridControl isn't completely initialized before it is visible for the first time, it is better to invoke the GridControl.ForceInitialize method to force this process in order to ensure the proper work of the BestFitColumns method.

I've created a sample project to demonstrate the main idea of how this works. Please test the project and let me know your results.

    Comments (2)

      Thank you very much Stas!

      DevExpress Support Team 8 years ago

        You are welcome, Greyce.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.