Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 292041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:08:38+00:00 2026-05-12T06:08:38+00:00

I am struggling with the WinForms DataGridView. I have a class, that I use

  • 0

I am struggling with the WinForms DataGridView. I have a class, that I use as element to be displayed:

public class BorderFlowHistoryElement
{
    public string nodeTitles { get; set; }
    public double borderFlowRatio { get; set; }
    ...
}

I created a list of these elements:

List<BorderFlowHistoryElement> clusterHistory

which contains a list of thise elements, that should be displayed in my DataGridView. I bound the list at the DataSource of the Grid:

dataGridViewCluster.DataSource = clusterHistory;

Now the DataGridView displays the list. Now I want to format the columns which display the double values to display 5 digits. I tried it with:

dataGridViewCluster.Columns[1].DefaultCellStyle.Format = "n5";

but this has no effect on the column. Anyone knows, how I can do it right?
Additionally, I want to size the columnwidth to optimal fit for the largest entry.

Thanks in advance,
Frank

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:08:38+00:00Added an answer on May 12, 2026 at 6:08 am

    I have replicated what you have done and I had no issue whatsoever. Have you validated your data to ensure that you can actually get the results that you want?

    Here is what I did just for your reference:

    private void button1_Click(object sender, EventArgs e)
        {
            IList<BorderFlowHistoryElement> clusterHistory = FillClusterHistory();
    
            dataGridView1.DataSource = clusterHistory;
    
            dataGridView1.Columns[1].DefaultCellStyle.Format = "n5";
    
            dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
    
        }
    
        private static IList<BorderFlowHistoryElement> FillClusterHistory()
        {
            IList<BorderFlowHistoryElement> clusterHistory = new   List<BorderFlowHistoryElement>();
    
    
            for(int i = 5000; i < 5020; i++)
            {
                BorderFlowHistoryElement element = new BorderFlowHistoryElement();
    
                element.nodeTitles = Guid.NewGuid().ToString();
    
                element.borderFlowRatio = i * 3.3.1415672467234823499821D;
    
                clusterHistory.Add(element);
            }
    
            return clusterHistory;
        }
    }
    
    public class BorderFlowHistoryElement
    {
        private string _NodeTitles;
        private double _BorderFlowRatio;
    
        public string nodeTitles
        {
            get { return _NodeTitles; }
            set { _NodeTitles = value;}
        }
    
        public double borderFlowRatio
        {
            get { return _BorderFlowRatio; }
            set { _BorderFlowRatio = value;}
        }
    }
    

    I hope that helps in some fashion. As you can see you can do the auto sizing as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm struggling to separate the dependencies in the following code: public static SiteConnector ConnectToSite(String
I am struggling on something that, I am sure, should be easy. I have
I'm struggling with ways how to input user preferences for given set. I have
I have an WinForms application with this Main Form : ICountRepository countRepository; public MainForm(ICountRepository
I'm struggling to find the right terminology here, but if you have jQuery object...
I am struggling with the route setup for a Rails application. I have installed
I'm struggling to get around the 404 errors from asp.net mvc beta when deploying
During my days doing Winforms development, I constantly found myself struggling against System.Windows.Forms controls.
All of the WinForms wizards I've written in the past have a high degree
I have an existing WinForms application for which I'm now designing new bits in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.